Skip to content

TarunISCO/caesar_cipher_decrypter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Caesar Cipher Decrypter

Caesar Cipher

In Cryptography, a Caesar Cipher, also known as the Shift Cipher, Caesar Shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

Caesar Cipher Example

Plain Text : THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

Cipher Text : QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

Deciphering is done in reverse, with a right shift of 3.

Modular Arithmetic

The encryption can also be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A → 0, B → 1, ..., Z → 25. Encryption of a letter x by a shift n can be described mathematically as,

Encryption

Decryption is performed similarly,

Decryption

The replacement remains the same throughout the message, so the cipher is classed as a type of monoalphabetic cipher as compared to polyalphabetic cipher.

Writing the Script

How Caesar Cipher works is that it shifts the characters(or letters) in the same order one step wither clockwise or counter clockwise. Keeping this in mind, I started writing a script. Here’s what this script does:

  • Takes the user input of Cryptic(ciphertext) message.
  • Generates all of the 26 possible keys.
  • Using each key, generates a possible decrypt.
  • Checks with the common and valid English words.
  • Calculates the probability.
  • If it has a probability of greater than 20, prints the decrypt(s).

Library Used

To verify if the decrypted words belong to the proper English dictionary : Enchant

Download Enchant from terminal using pip as pip install pyenchant