i am trying to implement ceaser's cipher in the generic sense by rotating the digits by integer n.i am trying to find out the pairs of these from a file containing words.
this what i've done so far,
from string import *
d = dict()
l = []
for i in range(ord('a'),ord('z')+1):
d[i] = chr(i)
def rotate_word(word,n):
global l
for i in range(0,len(word)):
k = ord(word[i]) + n
if k > ord('z'):
k %= ord('z')
elif k < ord('a'):
k = k % ord('a') + ord('z') - ord('a') + 1
l.append(chr(k))
return "".join(l)
wordlist = []
c_wordlist = []
r_wordlist = []
fin = open('mywords.txt','r')
for word in fin:
word = word.strip()
wordlist.append(word)
c_wordlist.append(word)
wordlist.sort()
c_wordlist.sort()
for i in wordlist:
print i
r_wordlist.append(rotate_word(i,7))
print r_wordlist[5]
for word in wordlist:
for i in r_wordlist:
print rotate_word(i,7)
if i == rotate_word(word,7):
print i," ",word,'\n'
i am getting really gibberish output and iam not able to find the error in it.