Published on: September 22, 2024
This program encrypts and decrypts messages using three different cryptographic methods:
Caesar Cipher, Linear Cipher, and RSA Cryptography.
It was developed in a Linux Ubuntu environment using C++.
- Select from three cipher methods: Caesar Cipher, Linear Cipher, or RSA
- Support for key discovery in Linear Cipher
- Built-in brute-force decryption for unknown Linear Cipher keys
- Public and private key generation for RSA encryption
- Improved RSA encryption capacity (1 β 9 letters) using Boost Multiprecision (
cpp_int) - Optimized RSA decryption (from hours β seconds) with modular exponentiation improvements
A simple shift cipher where each letter is shifted by a fixed number of places.
Encrypted Letter = (Original Letter + 3) mod 26
Input: hello my name is Jacob
Output: khoor pb qqph lv mdfre
The user can input the encrypted message to retrieve the original text.
A more complex shift cipher that follows the formula:
Encrypted Letter = (a * Original Letter + b) mod 26
Where a must be relatively prime to 26.
a = 21, b = 23
Input: nice to meet you
Output: kjnd gf pddg hfb
- Decrypt with (a, b) keys: Input known values of a and b to retrieve the original message.
- Decrypt without (a, b) keys: The program will try all possible 311 (a, b) combinations and display potential decryptions.
- Find (a, b) keys: Given both the original and encrypted message, the program will calculate the encryption keys a and b.
Encrypted Message: kjnd gf pddg hfb
input keys: a = 21, b = 23
Original Message: nice to meet you
Encrypted Message: kjnd gf pddg hfb
results: all 311 combinations
Original Message: nice to meet you
Encrypted Message: kjnd gf pddg hfb
output keys: a = 21, b = 23
An asymmetric encryption method that uses public and private keys for secure message encryption.
- Public key (n, e)
n = p * q(product of two prime numbers)eis a randomly selected number relatively prime toΦ(n)
- Private key (d)
dis calculated such that:(e * d) β‘ 1 (mod Ξ¦(n))
Encrypted Message = (Original Message ^ e) mod n
Original Message = (Encrypted Message ^ d) mod n
Input: berkeley
The program converts string into Original int: 2505120511180502
Encryption Result:
Message: 666434558223740174
Public Key e: 19
Public Key n: 1000000610000092769
Private Key d: 631579331368479259
Decryption Result:
Decrypted int: 2505120511180502
Decrypted Message: berkeley
- Each English letter requires two digits (e.g.,
z β 26). - The encryption process is limited by the size of public key
n, making it difficult to encrypt long messages due to integer overflow in C++.
πΉ (Now Updated!) Future Improvement: Exploring large number handling in C++ and optimizing modular arithmetic with exponentiation.
β
Increased encryption capacity (1 β 9 letters) using Boost Multiprecision (cpp_int)
β
Reduced decryption time from hours β seconds by optimizing modular exponentiation
- C++ Compiler (g++)
- Linux Ubuntu Environment
- Boost Multiprecision Library
make # Generates 'a.out'
./a.out
π Happy Encrypting & Decrypting!








