Skip to content

Simple cipher contains simple implementations of cryptography and cryptoanalysis on Caesar's Cipher, Vigenere's Cipher, and One Time Pads.

Notifications You must be signed in to change notification settings

empobla/simpleCiphers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkedIn


Simple Ciphers

Simple implementations of cryptography and cryptoanalysis on Caesar's Cipher, Vigenere's Cipher, and One Time Pads.

Table of Contents
  1. About The Project
  2. Abilities Mastered
  3. Getting Started
  4. Usage
  5. License
  6. Contact
  7. Acknowledgments

About The Project

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

(back to top)

Caesar's Cipher

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.

(back to top)

Vigenere's Cipher

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:

  1. Divides the ciphertext's characters into 4 groups ('hello world' would be divided into [ ['h','o','r'],['e', ' ', 'l'],['l','w','d'],['l','o']).
  2. Finds the top 4 most occurrent characters in each group.
  3. 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.
  4. Generates all the possible 4 lettered keys that the ciphertext could have (256 possible keys).
  5. 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.
  6. Asks the user to pick one of the top 4 most possible plain texts and outputs the plaintext and key to a .txt file.

(back to top)

One Time Pad

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.

(back to top)

Built With

Python

(back to top)

Abilities Mastered

  • 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

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Installation

  1. Clone the repo
    git clone https://github.com/empobla/simpleCiphers.git

(back to top)

Usage

Caesar's Cipher Script

With this script, you can:

  1. Cipher a message with a key
  2. Decipher a message with a key
  3. 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:

  1. cd into the project's directory
    cd simpleCiphers
  2. Run caesar.py
    python caesar.py

Vigenere's Cipher Script

With this script, you can:

  1. Cipher a message with a key
  2. Decipher a message with a key
  3. 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:

  1. cd into the project's directory
    cd simpleCiphers
  2. Run vigenere.py
    python vigenere.py

One Time Pad Script

With this script, you can:

  1. Cipher a message
  2. 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:

  1. cd into the project's directory
    cd simpleCiphers
  2. Run onetimepad.py
    python onetimepad.py

(back to top)

License

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.

(back to top)

Contact

Emilio Popovits Blake - Contact

Project Link: https://github.com/empobla/simpleCiphers

(back to top)

Acknowledgments

(back to top)

About

Simple cipher contains simple implementations of cryptography and cryptoanalysis on Caesar's Cipher, Vigenere's Cipher, and One Time Pads.

Topics

Resources

Stars

Watchers

Forks

Languages