Alice wants to send a secret message to Bob, for example:
The most basic example of a cryptographic cipher is the shift cipher. When utilizing the shift cipher the key is an integer is selected between 0 and 25 (for the English alphabet) which is used to determine how far to shift the alphabet. For example if a Key of 5 is used the cipher would look like the following table where the first row is the input letter, and the second row is the corresponding output letter.
In addition to shifting the message must first be transformed to remove punctuation, spaces and capitalization, as this can give hints to an attacker of the content.
Our Example Message is first transformed from “Hello, World!” to HELLOWORLD
Next the Shift is applied which produces the cipher text: “MJQQTBTWQI”
Decryption is simple, Shift the ciphertext to the left by the key (or right by 26 – key, e.g., 21)
Insecurity of the Shift Cipher
The key space is small (only 26 for the English alphabet) and easily brute forcible.
That is, try every key until the plain text is revealed. This approach makes the assumption that the attacker will know when to stop the brute force, in this example, words from the English Dictionary are returned.
Key = 0 : MJQQTBTWQI
Key = 1 : LIPPSASVPH
Key = 2 : KHOORZRUOG
Key = 3 : JGNNQYQTNF
Key = 4 : IFMMPXPSME
Key = 5 : HELLOWORLD – Key Found
Letter’s always encrypt to the same ciphertext for a given key. Example, L in the \”HELLOWORLD\” example always produced the ciphertext Q. This allows for a frequency analysis to be performed allowing for an attacker to guess the key with high degree of success base on the number of repeated characters.
Shift Cipher Example and Source Code
A sample python implementation of the Shift Cipher can be found on our github here: https://github.com/bscain/Cryptography/blob/master/shift_cipher.py
import shift_cipher cipher = shift_cipher.shift() cipherText = cipher.encrypt_message("Secret Message to be encrypted!") plainText = cipher.decrypt_message(cipherText) key = str(cipher.get_key())
Executing the above code results in the following output:
Encrypted Text is: ZLJYLATLZZHNLAVILLUJYFWALK Decrypted Text is: SECRETMESSAGETOBEENCRYPTED The key used for the encryption / decryption is: 7