Game Development Reference
In-Depth Information
14 - Caesar Cipher
55.
56. print('Your translated text is:')
57. print(getTranslatedMessage(mode, message, key))
This is the main part of our program. We call each of the three functions we have defined
above in turn to get the mode, message, and key that the user wants to use. We then pass
these three values as arguments to getTranslatedMessage() , whose return value (the
translated string) is printed to the user.
Brute Force
That's the entire Caesar Cipher. However, while this cipher may fool some people who
don't understand cryptography, it won't keep a message secret from someone who knows
cryptanalysis. While cryptography is the science of making codes, cryptanalysis is the
science of breaking codes.
Do you wish to encrypt or decrypt a message?
encrypt
Enter your message:
Doubts may not be pleasant, but certainty is absurd.
Enter the key number (1-26)
8
Your translated text is:
Lwcjba uig vwb jm xtmiaivb, jcb kmzbiqvbg qa ijaczl.
The whole point of cryptography is that so if someone else gets their hands on the
encrypted message, they cannot figure out the original unencrypted message from it. Let's
pretend we are the code breaker and all we have is the encrypted text:
Lwcjba uig vwb jm xtmiaivb, jcb kmzbiqvbg qa ijaczl.
One method of cryptanalysis is called brute force. Brute force is the technique of trying
every single possible key. If the cryptanalyst knows the cipher that the message uses (or at
least guesses it), they can just go through every possible key. Because there are only 26
possible keys, it would be easy for a cryptanalyst to write a program than prints the
decrypted ciphertext of every possible key and see if any of the outputs make sense. Let's
add a brute force feature to our program.
Adding the Brute Force Mode to Our Program
First, change lines 7, 9, and 12 (which are in the getMode() function) to look like the
following (the changes are in bold):
5. def getMode():
Search WWH ::




Custom Search