A Command line tool for Cipher Decryption using Genetic Algorithms and Natural Language Processing (NLP).
Report Bug
Ever thought how Natural language processing can be used for decryption of a cipher text? Well, here is the answer!
D-CRYPTOR is capable of encrypting and decrypting cipher text using Genetic Algorithm and Natural language processing (NLP).
Key Idea : After learning the probability likelihoods of normal english text, we can mutate the cipher (swapping) to minimize the difference of probability likelihood to plain english text. This mutation would be closed to the original mapping thus deciphered text.
High level Overview :
- A encoded text is generated using a random character-character mapping (source :
encoder.py
) - Now, for the decoding purpose following steps are performed:
- A Markov Matrix of bi-grams probabilities is generated from the training data
train.txt
. - We extend this to generate probabilities for the whole sequence and normalise to range (0,1).
- Now, generate random pool of DNA (a list of lowercase ascii characters) and shuffle them.
- To mutate, we take few candidates from the pool and generate probability score till number of iterations or out best score doesn't improve.
- A Markov Matrix of bi-grams probabilities is generated from the training data
- Now, we use this best likelihood score character mapping and apply to cipher text and obtain deciphered sentence.
- To make decryption process interesting, script uses
truecasing.py
which tries to reterive the original casing of decyphered text without knowing of it in the first place.
LIMITATIONS
- D-CRYPTOR cannot decrypt sentences with very few words as a 26 character mapping is harder to learn from it.
- Being a randomized algorithm, it might be possible that you get different result on successive runs.
- Does not decode punctuations.
To get a local copy up and running follow these simple example steps.
- Python
To check, if python is installed, type python
in command line. If this opens python3
interpreter then you are good to go.
else, python3
follow this link to download the latest version.
- Git
You can download the latest version of git
here.
- Clone the repo
git clone https://github.com/A-lone-Contributer/D-CRYPTOR.git
- Install the dependencies
pip install -r requirements.txt
- Download
distributions.obj
file which is a dependency oftruecasing.py
using this link. Extract the downloaded file and place it in the script directory.
- To run D-CRYPTOR, run the
master.py
file.
python master.py
NOTE: If python master.py
does not work, try using python3 master.py
instead.
- A intro splash screen would be displayed that looks something like this:
NOTE: You can press
Enter
to skip the animation screen.
- Now, you will be directed to a menu. Choose the first option (if not done before)
- After selecting the first option, you will be given a text box where you can write your original message which you want to encode and decode. You can either type of paste the copied text.
NOTE: Follow prompts written on the top of text field.
- Press
CTRL+G
to execute and obtain the encrypted message. This message is also saved in a text file namedencoded_text.txt
. After encryption, the cipher will look something like this
- As, we have generated the encrpted text, we can directly decypher the text. So, navigate to the decryption option on the menu and press
Enter
. A splash screen like this will be displayed.
- Final decoded text will be displayed after sometime.
NOTE: Running time of the algorithm depends on PC Specs and the length of the plain text being deciphered.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the Apache-2.0 License. See LICENSE
for more information.
Nishkarsh Tripathi : [email protected]
Project Link : D-CRYPTOR