Hey, it's me again. I have a Ceaser Cypher here:
letters=list("abcdefghijklmnopqrstuvwxyz")
def Encrypt():
for i in range(int((len(word)-1))):
curletter="".join(letters).find(word[i])
if (curletter+key)>(25):
if (curletter+key)<0:
i=(curletter+key)
i=[(curletter+key)-(curletter+key)]
else:
i=(curletter+key)-(25)
print (curletter+key)
word[i]=letters[curletter+key]
return
def Decrypt():
return
word=list(input("Type in some letters:"))
key=int(input("Type in a key:"))
choice=int(input("1) Encrypt\n2) Decrypt\n:"))
if choice==1:
Encrypt()
else:
Decrypt()
print("".join(word))
If you run it and type in something that is 26 or more letters (no spaces) and you use a key of 1, it runs, and you get an index error. However, when I used print to see why letters[currentletter+key] was out of range, the number preceding it was 26, when the list only goes to 25. I see no reason why this code:
if (curletter+key)>(25):
if (curletter+key)<0:
i=(curletter+key)
i=[(curletter+key)-(curletter+key)]
else:
i=(curletter+key)-(25)
Doesn't filter out numbers larger then 25. i is the "for" variable, currentletter is the list number of the letter you're on (a=0, b=1, c=2 etc). Any help from some python coding gurus would be much appreciated.