Python, encryption | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python, encryption

alpha = 'abcdefghijklmnopqrstuvwxyz ' output = " " input_mode = "" while input_mode != 0: input_mode = input(" [e]ncrypt or [d]ecrypt: ") if input_mode == 'e': word = input(" Enter a lowercase word: ") for letters in word: indexed = alpha.find(letters) output += alpha[25-indexed] print(output) elif input_mode == 'd': word = input(" Enter a decryption: ") for letters in word: indexed = alpha.find(letters) output += alpha[25+indexed] output += alpha[indexed] print(output) else: input_mode != 'e' or input_mode != 'd' print(" Try again . . . ") Why does this not work with decryption I want it to go from -25 to 25? Why does it now work?

17th Apr 2019, 3:38 AM
Ivan
3 Answers
+ 1
Your list indices are out of range. In encryption mode, 25-indexed may get in the negative range which is alright because negative list indices are allowed. But 25+indexed in decryption mode doesn't work. You're trying to access element 50+ of a list with only 27 elements. Also, the second line from the bottom is not a valid statement
17th Apr 2019, 4:48 AM
Anna
Anna - avatar
0
elif input_mode == 'd': word = input(" Enter a decryption: ") for letters in word: indexed = alpha.find(letters) output += alpha[25+indexed] output += alpha[indexed] print(output) I'm trying to figure out why this doesn't work? May someone help me.
17th Apr 2019, 3:40 AM
Ivan
0
yeah, i was testing some stuff i figured it out by just making a alpha2 with the alphabet backwards Anna 😂
17th Apr 2019, 5:07 AM
Ivan