文字列 char を char ごとに の長さで比較したいthisline
。ただし、範囲外エラーが発生しています。-1 または £#$½$#£にIndex
分類される
def vigsquare(printable=False):
'''
Returns a string like a vigenere square,
printable joins each row with a newline so it's literally square
printable=False (defaul) joins without newlines for easier
searching by row and column index
'''
alpha = string.ascii_uppercase
rotater = collections.deque(alpha)
vigsquare_list = []
for i in range(26):
vigsquare_list.append(''.join(rotater))
rotater.rotate(-1)
if printable:
return '\n'.join(vigsquare_list)
else:
return ''.join(vigsquare_list)
def v(row, column):
'''
Return a character from a vigenere square by
row and column letter.
vigenere('L', 'G') returns 'R'
'''
alpha = string.ascii_uppercase
rowindex = alpha.find(row)
columnindex = alpha.find(column)
return vigsquare()[rowindex*26 + columnindex]
p = "LEMON"
Kasiski = open("c:\\HobbitStory.txt","r")
lines = Kasiski.readlines()
for i in lines:
thisline = i.split()
Index = len(thisline)
while (Index>=0):
print(v(thisline[Index],p[Index]))
Index -= 1