Simple implementations of cryptography and cryptoanalysis on Caesar's Cipher, Vigenere's Cipher, and One Time Pads.
Table of Contents
Simple cipher contains simple implementations of cryptography and cryptoanalysis on Caesar's Cipher, Vigenere's Cipher, and One Time Pads.
All three programs use the following alphabet: 'abcdefghijklmnopqrstuvwxyz '
.
caesar.py
and vigenere.py
both assume that the ciphertext is in english and use the following 5 words to cryptoanalyse and decipher a ciphertext with an unknown key:
[' the ', ' be ', ' to ', ' of ', ' and ']
A list of 100 words that occur most frequently in written English is given below, based on an analysis of the Oxford English Corpus. Source
caesar.py
can cipher a user's input plaintext with a given key, decipher a user's input ciphertext with a known given key, and find an unknown key for an input ciphertext ciphered with caesar's cipher (in this case the ciphertext is input as a .txt
file in ./input
and chosen in the CLI).
The approach taken to cryptoanalyse and decipher an ciphertext with an unknown key is to assume that ' '
is one of the most occurrent characters in the ciphertext and proceeding to find the top most occurrent characters in the ciphertext.
vigenere.py
can cipher a user's input plaintext with a given key, decipher a user's input ciphertext with a known given key, and find an unknown key for an input ciphertext (in this case the ciphertext is input as a .txt
file in ./input
and chosen in the CLI).
Note: vigenere.py
is made only to find unknown keys that are 4 characters in length and it assumes that the ciphertext is in english.
When finding an unknown key for an input ciphertext, vigenere.py
assumes that the original unknown plaintext has the following alphabet: 'abcdefghijklmnopqrstuvwxyz '
and does not contain line breaks or any other characters not included in the alphabet. It finds the unknown ciphertext through the following steps:
- Divides the ciphertext's characters into 4 groups (
'hello world'
would be divided into[ ['h','o','r'],['e', ' ', 'l'],['l','w','d'],['l','o']
). - Finds the top 4 most occurrent characters in each group.
- Assuming
' '
is one of the top 4 most occurrent characters in each group, it finds the appropriate shifts for each characacter of the top 4 most occurrent characters per group. - Generates all the possible 4 lettered keys that the ciphertext could have (256 possible keys).
- Uses 4 threads that each decipher the text with 64 possible keys and count the number of appearances of the top 5 most common words in the english language (the, be, to, of, and), and each returns the key which had the most total matches of these substrings.
- Asks the user to pick one of the top 4 most possible plain texts and outputs the plaintext and key to a
.txt
file.
onetimepad.py
will cipher a user's input plaintext with a randomly generated key which is the length of the user's input plaintext, and given the key and the ciphertext, it can decipher the ciphertext back into a plain text.
This program uses the function vigenere(text, key, cipher)
and the only thing it does differently from vigenere.py
is that it generates a completely random key which it inputs into that function to cipher the plaintext. onetimepad.py
also uses the same function to decipher the given ciphertext with a given key.
- Enciphering and Deciphering a plaintext/ciphertext with a key using Caesar's Cipher, Vigenere's Cipher, and a One Time Pad
- Implementation of Caesar's Cipher, Vigenere's Cipher, and One Time Pad
- Decipher through cryptoanalysis a ciphertext with an unknown key enciphered with Caesar's Cipher or Vigenere's Cipher
To get a local copy up and running follow these simple example steps.
- Clone the repo
git clone https://github.com/empobla/simpleCiphers.git
With this script, you can:
- Cipher a message with a key
- Decipher a message with a key
- Decrypt a message in a file.
In order to decrypt a message in a file, you must save the file as a .txt
in the input/
directory. The output of the decrypted file will be found in outputs/original_file_name.txt
, with the key of the cipher and the decrypted message.
In order to run this script, follow the following instructions:
cd
into the project's directorycd simpleCiphers
- Run
caesar.py
python caesar.py
With this script, you can:
- Cipher a message with a key
- Decipher a message with a key
- Decrypt a message in a file.
In order to decrypt a message in a file, you must save the file as a .txt
in the input/
directory. The script will then analyze the ciphertext and will find possible keys that decipher the given text. After chosing the key that deciphers the ciphertext, the script will output the plain text as an output file. The output of the decrypted file will be found in outputs/original_file_name.txt
, with the key of the cipher and the decrypted message.
In order to run this script, follow the following instructions:
cd
into the project's directorycd simpleCiphers
- Run
vigenere.py
python vigenere.py
With this script, you can:
- Cipher a message
- Decipher a message
When enciphering a plaintext message with this script, the script will create a One Time Pad, encipher the plaintext message, and output the ciphertext and the key to the console. These outputs can be used with this script's second option, which will decipher the message.
In order to run this script, follow the following instructions:
cd
into the project's directorycd simpleCiphers
- Run
onetimepad.py
python onetimepad.py
This project is property of Emilio Popovits Blake. All rights are reserved. Modification or redistribution of this code must have explicit consent from the owner.
Emilio Popovits Blake - Contact
Project Link: https://github.com/empobla/simpleCiphers