Simple cryptographic substitution-based cipher for encoding plaintext.
Project description
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
usingpip
:-
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
.
-
Before use, navigate to the intended installation location, and create a new directory.
-
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.
-
Install all dependencies for this package within the installation directory using the following command:
-
pip install -r requirements.txt
-
-
(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 theMyCaesarCipher
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 toTrue
. -
{'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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file MyCaesarCipher-0.4.1.tar.gz
.
File metadata
- Download URL: MyCaesarCipher-0.4.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9200d1c0e2c6291f959e42ff7c6f43c629196d22bcd497a650c98a8f4911b912 |
|
MD5 | e45882f7129e64ccf35a280ca007d4ba |
|
BLAKE2b-256 | 41ce6c034ba5b3c3744264f45fef577f7695a56907b9c2a6b1add48ea38378c0 |
File details
Details for the file MyCaesarCipher-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: MyCaesarCipher-0.4.1-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94a1fb9f371c6dc41199a51b8636e67e3e90047bbe2d0abb6796ca4774a5b2b6 |
|
MD5 | dbecbcf49ed09dcbd1e4023ce4ee2000 |
|
BLAKE2b-256 | efa16a41a79eeb273eed337b8e6de3d7382ed491c08e7a9aec1bf2d759a50c80 |