'14:14 31/05/2018
'DIFF ALGORITHM
string s1="00123456789abcdefghijklmnopqrstuvwxyz"
string s2="0123456789abcdefghijklMNopqrstuvwxyz"
int ls1=len(s1)
int ls2=len(s2)
int d=1
int lb
int lw
int i
int j
int k1
int k2
int bg1
int bg2
int en1
int en2
string w1
string w2
string w3
string w4
'
i=1
lb=ls1
do
  w1=mid(s1,i,lb)
  lw=len w1
  if lw>0 then
    j=instr(1,s2,w1)
  else
    j=0
  end if
  '
  if j=0 then
    i+=lb 'try matching next block
    if i>ls1 then
      d=d+d 'to split size of block
      lb=ls1\d
      if lb=0 then
        lw=0
        exit do 'fail to match
      end if
      i=1 'restart with first block
    else
      i+=lb 'try next block
    end if
  else 'j>0 'match found
    'extend matching zone
    k1=i
    k2=j
    do  'extend left
      k1-- : k2--
      if k1<1 then exit do
      if k2<1 then exit do
      if asc(s1,k1)<>asc(s2,k2) then exit do
    loop
    bg1=k1+1
    bg2=k2+1
    k1=i+lw-1
    k2=j+lw-1
    do 'extend right
      k1++ : k2++
      if k1>ls1 then exit do
      if k2>ls2 then exit do
      if asc(s1,k1)<>asc(s2,k2) then exit do
    loop
    en1=k1
    en2=k2
    w4=mid(s2,bg2,en2-bg2) 'matching segment
    exit do
  end if
loop
if j then
  if bg2>1 then w2=left s2,bg2-1
  if en2<=ls2 then w3=mid s2,en2 
  print w1 " " d chr(13,10) w4 chr(13,10,62,62) w2 chr(13,10,62,62) w3
  print left(s1,bg1-1)+string(en1-bg1,"-")+mid(s1,en2)
end if
