Skip to content

Latest commit

 

History

History
220 lines (124 loc) · 6.32 KB

README.md

File metadata and controls

220 lines (124 loc) · 6.32 KB

MyCaesarCipher

Simple cryptographic substitution-based cipher for encoding plaintext.


About

  • The Caesar Cipher is one of the most simple and well-known encryption techniques.

    • Each letter in the plaintext entry is replaced by a letter found at a certain number of positions down the alphabet.
  • This project was created as an exercise while I was taking the "Cracking Codes with Python" course - which I highly recommend for both beginners and experienced Python programmers interested in cryptography!


Installation

Using pip (Recommended)

Easiest method. Highly recommended over manual installation.

  • Run the following to install MyCaesarCipher using pip:

    • pip install MyCaesarCipher
  • You should now be able to import/run MyCaesarCipher within your Python environment by entering the following:

    • >>> from MyCaesarCipher import CaesarCipher
      ...
  • Done!


Manual Installation

Not recommended. Only use this method if you are unable to install using pip.

  1. Before use, navigate to the intended installation location, and create a new directory.

  2. Please only do one of the following:

    • A. Clone repository with the git client of your preference.
    • B. Download and extract the source code zip archive from the "releases" page to the newly created directory.
  3. Install all dependencies for this package within the installation directory using the following command:

    • pip install -r requirements.txt
  4. (Optional) move the installation directory to "~Python/Libs/site_packages/" to be able to import this package to a Python environment like any other importable package.

  • Done!

Usage

  • Within a Python environment or .py project, simply import the MyCaesarCipher module to start encryption/decryption of ciphers.

Text Encryption

  • For encrypting text, use the CaesarCipher.encrypt class method:

    • >>> from MyCaesarCipher import CaesarCipher
      
      >>> cipher = CaesarCipher() # Create new class instance.
      >>> txt = 'Test Cipher'
      >>> cipher.encrypt(text=txt, key=15, stdout_output=True)
      
      ------------------------------------
      
      > Original Txt : Test Cipher
      
      > Shift-Key : 15
      
      > Encrypted Result: Ithi Rxewtg
  • Therefore the final encrypted result of "Test Cipher" using a shift key of 15 is:

    • "Ithi Rxewtg".
  • Note that the key parameter is optional, and if not provided, a random key between 1 and 25 will be generated:

    • >>> cipher.encrypt('Test Cipher', stdout_output=True)
      
      ------------------------------------
      
      > Original Txt : Test Cipher
      
      > Shift-key : 19
      
      > Encrypted Result: Mxlm Vbiaxk

    • >>> cipher.encrypt('Test Cipher', stdout_output=True)
      
      ------------------------------------
      
      > Original Txt : Test Cipher
      
      > Shift-key : 24
      
      > Encrypted Result: Rcqr Agnfcp

    • >>> cipher.encrypt('Test Cipher', stdout_output=True)
      
      ------------------------------------
      
      > Original Txt : Test Cipher
      
      > Shift-key : 4
      
      > Encrypted Result: Xiwx Gmtliv

Text Decryption

  • For decrypting text, use the CaesarCipher.decrypt class method:

    • >>> from MyCaesarCipher import CaesarCipher
      
      >>> cipher = CaesarCipher() # Create new class instance.
      >>> decryption = cipher.decrypt(text='Ozno Xdkczm', stdout_output=True)
      
      ------------------------------------
      
      > Decrypted Shift-Key 0 : Ozno Xdkczm
      
      > Decrypted Shift-Key 1 : Nymn Wcjbyl
      
      > Decrypted Shift-Key 2 : Mxlm Vbiaxk
      
      > Decrypted Shift-Key 3 : Lwkl Uahzwj
      
      > Decrypted Shift-Key 4 : Kvjk Tzgyvi
      
      > Decrypted Shift-Key 5 : Juij Syfxuh
      
      > Decrypted Shift-Key 6 : Ithi Rxewtg
      
      > Decrypted Shift-Key 7 : Hsgh Qwdvsf
      
      > Decrypted Shift-Key 8 : Grfg Pvcure
      
      > Decrypted Shift-Key 9 : Fqef Oubtqd
      
      > Decrypted Shift-Key 10 : Epde Ntaspc
      
      > Decrypted Shift-Key 11 : Docd Mszrob
      
      > Decrypted Shift-Key 12 : Cnbc Lryqna
      
      > Decrypted Shift-Key 13 : Bmab Kqxpmz
      
      > Decrypted Shift-Key 14 : Alza Jpwoly
      
      > Decrypted Shift-Key 15 : Zkyz Iovnkx
      
      > Decrypted Shift-Key 16 : Yjxy Hnumjw
      
      > Decrypted Shift-Key 17 : Xiwx Gmtliv
      
      > Decrypted Shift-Key 18 : Whvw Flskhu
      
      > Decrypted Shift-Key 19 : Vguv Ekrjgt
      
      > Decrypted Shift-Key 20 : Uftu Djqifs
      
      > Decrypted Shift-Key 21 : Test Cipher # <-- Correct Result
      
      > Decrypted Shift-Key 22 : Sdrs Bhogdq
      
      > Decrypted Shift-Key 23 : Rcqr Agnfcp
      
      > Decrypted Shift-Key 24 : Qbpq Zfmebo
      
      > Decrypted Shift-Key 25 : Paop Yeldan
  • The CaesarCipher.decrypt method will return all possible shifted-key variations of the given encrypted text as a dictionary.

    • This is NOT printed to stdout even if the stdout_output parameter is set to True.

    • {'Ozno Xdkczm': 0, 'Nymn Wcjbyl': 1, 'Mxlm Vbiaxk': 2, 'Lwkl Uahzwj': 3, 'Kvjk Tzgyvi': 4, 'Juij Syfxuh': 5, 'Ithi Rxewtg': 6, 'Hsgh Qwdvsf': 7, 'Grfg Pvcure': 8, 'Fqef Oubtqd': 9, 'Epde Ntaspc': 10, 'Docd Mszrob': 11, 'Cnbc Lryqna': 12, 'Bmab Kqxpmz': 13, 'Alza Jpwoly': 14, 'Zkyz Iovnkx': 15, 'Yjxy Hnumjw': 16, 'Xiwx Gmtliv': 17, 'Whvw Flskhu': 18, 'Vguv Ekrjgt': 19, 'Uftu Djqifs': 20, 'Test Cipher': 21, 'Sdrs Bhogdq': 22, 'Rcqr Agnfcp': 23, 'Qbpq Zfmebo': 24, 'Paop Yeldan': 25}
  • Generally, the most legible key output will be the correct decrypted text (assuming the encrypted text was legible initially).

  • Regardless, the correct output MUST be one of the output values due to the limitations of the algorithm being tied to the length of the alphabet [26] and the number of possible integers [0-9].

    • This is also the reason why the algorithm is not recommended for serious real-world cryptography use cases, as it is rather simple to decipher Caesar-Cipher encrypted text.

Contact

  • If you have any questions, comments, or concerns that cannot be alleviated through the project's GitHub repository, please feel free to contact me through my email address:

    • schloppdaddy@gmail.com