Game Development Reference
In-Depth Information
key. Remember that if you do not know the correct key, the decrypted text will just be
garbage data.
Do you wish to encrypt or decrypt a message?
decrypt
Enter your message:
Gur fxl nobir gur cbeg jnf gur pbybe bs gryrivfvba, gharq gb n
qrnq punaary.
Enter the key number (1-26)
15
Your translated text is:
Rfc qiw yzmtc rfc nmpr uyq rfc amjmp md rcjctgqgml, rslcb rm y
bcyb afyllcj.
Caesar Cipher's Source Code
Here is the source code for the Caesar Cipher program. If you don't want to type all of
this code in, you can visit this topic's website at the URL
http://inventwithpython.com/chapter14 and follow the instructions to download the source
code. After you type this code in, save the file as cipher.py
cipher.py
This code can be downloaded from http://inventwithpython.com/cipher.py
If you get errors after typing this code in, compare it to the topic's code with the online
diff tool at http://inventwithpython.com/diff or email the author at
al@inventwithpython.com
1. # Caesar Cipher
2.
3. MAX_KEY_SIZE = 26
4.
5. def getMode():
6. while True:
7. print('Do you wish to encrypt or decrypt a
message?')
8. mode = input().lower()
9. if mode in 'encrypt e decrypt d'.split():
10. return mode
11. else:
12. print('Enter either "encrypt" or "e" or
"decrypt" or "d".')
13.
14. def getMessage():
15. print('Enter your message:')
16. return input()
17.
18. def getKey():
19. key = 0
20. while True:
21. print('Enter the key number (1-%s)' %
Search WWH ::




Custom Search