        character line*120
        character text(20000)*1
        integer nkey(40)
        logical match
        do 49 i=1,120
          line(i:i)=' '
  49    continue

        n=0
        open(8,file="Vigenere.code",form="formatted")
  1     read(8,1000,end=2)line
        write(*,1000)line
1000    format(a120)
        do 15 i=1,120
          nl=ichar(line(i:i))
          if(nl.ge.97.and.nl.le.122)then
            nl=nl-32
          end if
          if(nl.ge.65.and.nl.le.90)then
            n=n+1
            text(n)=char(nl)
          end if
  15    continue
        go to 1

  2     close(8)

        write(*,2000)(text(i),i=1,n)
 2000   format(60a1)

        do 56 i=3,6
          nmatch=0
          write(*,*)'Looking for matches with ',i,' letter strings'
          do 57 j=1,n-i-1
            do 57 k=j+1,n-i
              match = .true.
              do 58 l=1,i
                if(text(j+l-1).ne.text(k+l-1))match=.false.
  58          continue
              if(match)then
                write(*,*)(text(j+l-1),l=1,i),k-j,k,j
                nmatch = nmatch+1
              end if
  57      continue
              if(nmatch.eq.0)stop    
  56    continue
        stop
        end
