Skip to content

nvsriram/DeCipher

Repository files navigation

DeCipher

DeCipher is a user-friendly variable cipher with a catch.

This will work on most C++ IDEs. Just download the header files and add them all to the same folder as the .cpp file, compile and run! NOTE: You may have to change library paths in order to read the large.txt dictionary text file.
P.S. You can replace the clearscreen.hpp and ClearScreen() function header file with system("clear");,system("cls");,<curses.h> library or any OS specific clear screen command. The ClearScreen() function currently implements a flush-endlines-till-it-exceeds-screen-dimensions approach to achieve the same result as any of the previously mentioned options.

<asciiarmor.hpp>, <caesar.hpp> and <vigenere.hpp> header files correspond to their respective cipher and their implementation. It also defines a namespace that makes them easy to use. <clearscreen.hpp> header file defines one clear screen function that is used and two others that work based on the OS and included header files. <dictionary.hpp> header file implements the dictionary spellchecker by using the large.txt text file as its source file for the dictionary.

The program is very user-friendly and interactive. It starts by leading you to a pretty table of the various ciphers to choose from:

ASCII armor
ASCII armor is a binary-to-textual encoding converter. ASCII armor is a feature of a type of encryption called pretty good privacy (PGP). In this you are asked to enter the plaintext(std::string) and a key(long int). The function then:
  1. Creates pseudo-random hashing key derived from the key
  2. Uses the hashing key to encrypt the plaintext
  3. Converts to Base85 to get a console-printable ciphertext

The function also decodes said ciphertext and converts it back to plaintext. A good proof of execution of the program would have your initially entered plaintext match the decoded text.

Caesar Cipher
Caesar cipher is one of the earliest known and simplest ciphers. It is a type of replacement cipher in which each letter of the plaintext is 'moved' to a certain place under the alphabet. For example, with a shift of 1, A will be replaced by B, B becomes C, and so on until it cycles back to A. In this you are asked to enter the plaintext(std::string) and a whole number key(std::size_t). Based on the key, the program would perform one of the following:
  1. If they key is greater than 0, then treat the plaintext for what it is and perform the encryption and decryption shift based on the key
  2. If the key is 0, then treat the plaintext as a ciphertext and perform decryption using every possible key. Then perform the Bruteforce Dictionary to find the possible plaintexts.
Vigenère Cipher
The Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers, based on the letters of a keyword. It employs a form of polyalphabetic substitution. In this you are asked to enter the plaintext(std::string)and a alphabetic key(std::string). The program ignores case and assigns every alphabet to a shift value. For example, A/a is a shift of 0, B/b is a shift of 1 and so on. Based on the key, the function then:
  1. Shifts the first character of the plaintext by the shift determined by first character of the key. Second character will be shifted based on second character of key and so on.
  2. If the key is longer than plaintext, it'll move until plaintext length and be shifted by the characters that come under that length of key. However, if the plaintext is longer than the key, then the key repeats until plaintext has reached its end.
Bruteforce Dictionary
Although this is not a direct choice, it is an important part of the project. The Bruteforce Dictionary is used to implement a dictionary as a spellchecker to crack the plaintext for the Caesar cipher in this program but can be used for the other ciphers as well. This works as follows:
  1. First the dictionary is loaded from the file into a hashtable dynamically indexed by the first letters of the word. Hence we get twenty-six heads for the linked lists.
  2. Then the inputted ciphertext is decoded with a key that loops from 0 to 25. This way we get every possible input for the given output.
  3. Based on the input at every iteration, it is checked with the linked list corresponding to the first letter of the input. If it is present, it is displayed along with the key corresponding to the result.
In this manner, we manage to arrive at the logical input corresponding to the given output using bruteforce.

Just enter your choice, follow the instructions, and you should be good to go!
Enjoy!¯\_(ツ)_/¯