Department of Computer Sciences
Bahria University, Islamabad Campus
`
Object Oriented Programming
Project Report
Assignment # 4
(Project-Part II)
This is a Group Assignment of maximum 3 students. Students can also work
alone. Prepare Project Report including project description, features, source
code, and screen shots of outcome and submit on time. Report should be
properly formatted and should adhere to formal English.
Contents
Introduction:.............................................................................................................................. 3
Project Topic: ......................................................................................................................... 3
Section:................................................................................................................................... 3
Group Members:..................................................................................................................... 3
Project Description ..................................................................................................................... 3
Intro:...................................................................................................................................... 3
Overview: ............................................................................................................................... 3
Features ..................................................................................................................................... 3
1. Caesar Cipher:................................................................................................................ 3
2. Substitution Cipher:........................................................................................................ 3
3. Reverse Cipher: .............................................................................................................. 4
4. Biliteral Cipher:.............................................................................................................. 4
Functionality: ............................................................................................................................. 4
Implementation Details:.............................................................................................................. 4
Classes:................................................................................................................................... 4
1.1 Caesar Cipher:............................................................................................................ 4
1.2 Subtitution Cipher: ..................................................................................................... 5
1.3 Reverse Cipher: .......................................................................................................... 5
1.4 Biliteral cipher: ........................................................................................................... 5
Source Code ............................................................................................................................... 5
Output: .....................................................................................................................................42
Selecting: ...............................................................................................................................42
Picking shift:..........................................................................................................................42
Encrypting:............................................................................................................................43
Decrypting:............................................................................................................................43
Loop:.....................................................................................................................................44
File Handling:........................................................................................................................44
Encrypted..............................................................................................................................44
Introduction:
Project Topic:
Cryptic Vault: Encrypt/decrypt security secrets with Cryptography.
Section:
BS(CS)-2A
Group Members:
Abdul Wasay (01-134232-012).
Muhammad Bilal (01-134232-115).
Shafay Mirza (01-134232-131).
Project Description
Intro:
Secure-Vault is an easy-to-use command-line tool for encrypting and decrypting
messages with different ciphers, including custom formulas. It helps you protect
sensitive information and decode encrypted messages simply and effectively.
Overview:
This project implements various classical ciphers in C++ including Caesar,
Substitution, Reverse, Biliteral and Multiplicative ciphers. It allows users to encrypt
and decrypt messages using different methods.
Features
1. Caesar Cipher:
 Provides encryption and decryption with shifts of 3, 7, 13, and custom user-
defined shifts.
2. Substitution Cipher:
 Uses a predefined substitution map for encryption and decryption of
messages.
3. Reverse Cipher:
 Encrypts text by reversing it and decrypts text by reversing the encrypted
message.
4. Biliteral Cipher:
 Encodes and decodes text using a mapping of characters to binary
representations.
Functionality:
 Users can choose which cipher to use, whether to encrypt or decrypt, and the
specific parameters (shifts, text inputs).
 The program includes colorful console outputs for clarity and user interaction
which has been done with the help of windows.h library.
 The program has used iomanip library which helps the code to be in proper
sequence.
 The code also does file handling with the help of fstream library.
 We have used map library which allows you to use the map container. A map
is an associative container that stores elements in key-value pairs, where each
key is unique. It provides efficient retrieval, insertion, and deletion operations
based on keys.
 The program runs in a loop, allowing users to perform multiple operations
without restarting.
Implementation Details:
Classes:
1.1 Caesar Cipher:
 CaesarCipher_encryption: Base class for Caesar cipher encryption.
 Cipher1, Cipher2, Cipher3, CipherCustom: Subclasses of
CaesarCipher_encryption with different shift values.
 CaesarCipher_decryption: Base class for Caesar cipher decryption.
 Cipher4, Cipher5, Cipher6, CipherCustomDecryption: Subclasses of
CaesarCipher_decryption for decryption with different shifts.
1.2 Subtitution Cipher:
 SubstitutionCipher: Implements substitution cipher encryption and
decryption.
1.3 Reverse Cipher:
 ReverseCipherEncryption, ReverseCipherDecryption: Classes for reverse
cipher encryption and decryption.
1.4 Biliteral cipher:
 BaconCipher(Biliteral cipher): Implements Bacon cipher encoding and
decoding.
Source Code
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <map>
#include <algorithm>
#include <iomanip> // Aligning
#include <unordered_map>
using namespace std;
//*****************************************************************
******************************************************************
**************
// Parent Class
class CaesarCipher_encryption
{
protected:
int shift;
public:
CaesarCipher_encryption(int s) : shift(s % 26) {}
void SetConsoleTextColor(int textColor)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, textColor);
}
string encrypt(const string& text)
{
string result = "";
for (char ch : text)
{
if (isupper(ch))
{
result += char(int(ch + shift - 65) % 26 + 65);
}
else if (islower(ch))
{
result += char(int(ch + shift - 97) % 26 + 97);
}
else
{
result += ch; // Non-alphabetic characters remain unchanged
}
}
return result;
}
};
// Child class with shift 3
class Cipher1 : public CaesarCipher_encryption
{
public:
Cipher1() : CaesarCipher_encryption(3) {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(66) << "Enter Text for Cipher 1: ";
cin.ignore(); // Clear the buffer
SetConsoleTextColor(3);
getline(cin, text);
return text;
}
};
// Child class with shift 7
class Cipher2 : public CaesarCipher_encryption
{
public:
Cipher2() : CaesarCipher_encryption(7) {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(66) << "Enter Text for Cipher 2: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
// Child class with shift 13
class Cipher3 : public CaesarCipher_encryption
{
public:
Cipher3() : CaesarCipher_encryption(13) {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(66) << "Enter Text for Cipher 3: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
// Child class with user-defined shift
class CipherCustom : public CaesarCipher_encryption
{
public:
CipherCustom(int shift) : CaesarCipher_encryption(shift) {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(71) << "Enter Text for Custom Cipher: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
//*****************************************************************
******************************************************************
*************
class CaesarCipher_decryption
{
protected:
int shift;
public:
void SetConsoleTextColor(int textColor)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, textColor);
}
string decrypt(const string& a, int shift)
{
string result = a;
for (char& c : result)
{
if (isalpha(c))
{
char base = islower(c) ? 'a' : 'A';
c = (c - base - shift + 26) % 26 + base;
}
}
return result;
}
};
class Cipher4 : public CaesarCipher_decryption
{
public:
Cipher4() : CaesarCipher_decryption() {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(66) << "Enter Text for Cipher_3: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
class Cipher5 : public CaesarCipher_decryption
{
public:
Cipher5() : CaesarCipher_decryption() {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(66) << "Enter Text for Cipher_7: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
class Cipher6 : public CaesarCipher_decryption
{
public:
Cipher6() : CaesarCipher_decryption() {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(67) << "Enter Text for Cipher_13: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
class CipherCustomDecryption : public CaesarCipher_decryption
{
public:
CipherCustomDecryption() : CaesarCipher_decryption() {}
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
string input()
{
string text;
SetConsoleTextColor(12);
cout << setw(75) << "Enter Text for Custom Decryption: ";
SetConsoleTextColor(3);
cin.ignore(); // Clear the buffer
getline(cin, text);
return text;
}
};
//*****************************************************************
******************************************************************
**************
//Substitution cipher
class SubstitutionCipher
{
public:
map<char, char> encryptionMap;
map<char, char> decryptionMap;
SubstitutionCipher(map<char, char> map)
{
encryptionMap = map;
for (const auto& pair : map)
decryptionMap[pair.second] = pair.first;
}
string encrypt(const string& plaintext)
{
string ciphertext;
for (char c : plaintext)
{
if (encryptionMap.find(c) != encryptionMap.end())
{
ciphertext += encryptionMap[c];
}
else
{
ciphertext += c; // keep non-alphabetic characters unchanged
}
}
return ciphertext;
}
string decrypt(const string& ciphertext)
{
string decryptedText;
for (char c : ciphertext)
{
if (decryptionMap.find(c) != decryptionMap.end())
{
decryptedText += decryptionMap[c];
}
else
{
decryptedText += c; // keep non-alphabetic characters unchanged
}
}
return decryptedText;
}
};
//*****************************************************************
******************************************************************
**************
//Reverse Cipher
class ReverseCipherDecryption; // Forward declaration
class ReverseCipherEncryption
{
public:
string encrypt(const string& plainText)
{
string cipherText = plainText;
reverse(cipherText.begin(), cipherText.end());
return cipherText;
}
};
class ReverseCipherDecryption
{
public:
string decrypt(const string& cipherText)
{
string plainText = cipherText;
reverse(plainText.begin(), plainText.end());
return plainText;
}
friend string decryptUsingFriend(const ReverseCipherDecryption& dec, const
string& cipherText);
};
class UserInput
{
public:
void SetConsoleTextColor(int textColor)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, textColor);
}
string getInput(const string& prompt)
{
string input;
SetConsoleTextColor(12);
cout << prompt;
SetConsoleTextColor(3);
getline(cin, input);
return input;
}
};
void SetConsoleTextColor(int color)
{
// Function to set console text color for Windows
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
void WriteToFile(const string& filename, const string& encryptedText)
{
ofstream outFile(filename, ios::binary); // Open file in binary mode
if (outFile.is_open())
{
outFile.write(encryptedText.c_str(), encryptedText.size());
outFile.close();
}
else
{
cout << "Unable to open file: " << filename << endl;
}
}
string ReadFromFile(const string& filename)
{
string encryptedText;
ifstream inFile(filename, ios::binary); // Open file in binary mode
if (inFile.is_open())
{
inFile.seekg(0, ios::end);
int fileSize = inFile.tellg();
inFile.seekg(0, ios::beg);
char* buffer = new char[fileSize];
inFile.read(buffer, fileSize);
encryptedText.assign(buffer, fileSize);
delete[] buffer;
inFile.close();
}
else
{
cout << "Unable to open file: " << filename << endl;
}
return encryptedText;
}
string decryptUsingFriend(const ReverseCipherDecryption& dec, const string&
cipherText)
{
string plainText = cipherText;
reverse(plainText.begin(), plainText.end());
return plainText;
}
// Function to set cursor position
void SetCursorPosition(int x, int y) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) };
SetConsoleCursorPosition(hConsole, position);
}
//*****************************************************************
******************************************************************
*************
//Biliteral Cipher
class BaconCipher
{
private:
unordered_map<char, string> baconMap;
unordered_map<string, char> reverseBaconMap;
void initializeBaconCipher()
{
string baconCodes[26] =
{
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba", "aabbb",
"abaaa", "abaab", "ababa", "ababb", "abbaa", "abbab", "abbba", "abbbb",
"baaaa", "baaab", "baaba", "baabb", "babaa", "babab", "babba", "babbb",
"bbaaa", "bbaab"
};
for (char c = 'A'; c <= 'Z'; ++c)
{
baconMap[c] = baconCodes[c - 'A'];
reverseBaconMap[baconCodes[c - 'A']] = c;
}
}
public:
BaconCipher()
{
initializeBaconCipher();
}
string encode(const string& plaintext)
{
string encodedText;
for (char c : plaintext)
{
if (isalpha(c))
{
encodedText += baconMap[toupper(c)];
}
}
return encodedText;
}
string decode(const string& encodedText)
{
string decodedText;
for (size_t i = 0; i < encodedText.size(); i += 5)
{
string segment = encodedText.substr(i, 5);
if (reverseBaconMap.find(segment) != reverseBaconMap.end())
{
decodedText += reverseBaconMap[segment];
}
}
return decodedText;
}
};
//*****************************************************************
******************************************************************
**************
int main()
{
const int colors[] =
{
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15
};
// Color names corresponding to the color codes
const char* colorNames[] =
{
"Black", "Blue", "Green", "Aqua", "Red", "Purple", "Yellow", "White",
"Gray", "Light Blue", "Light Green", "Light Aqua", "Light Red", "Light
Purple", "Light Yellow", "Bright White"
};
SetConsoleTextColor(2);
cout << fixed << setw(85) << " Cryptic Vault" << endl << endl;
cout << fixed << setw(93) << " Wellcome To Cipher World <3" << endl;
char Z;
do {
int a;
SetConsoleTextColor(12);
cout << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << "1.Ceasar Cipher " << endl;
cout << "2.Substitution Cipher " << endl;
cout << "3.Reverse Cipher " << endl;
cout << "4.Biliteral Cipher " << endl;
SetConsoleTextColor(12);
cout << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> a;
cout << endl;
switch (a)
{
case 1: // Ceasar Cipher
{
int b;
SetConsoleTextColor(12);
cout << setw(40) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(32) << "1.For encryption" << endl;
cout << setw(32) << "2.For decryption" << endl;
SetConsoleTextColor(12);
cout << setw(35) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> b;
cout << endl;
switch (b)
{
case 1:
{
int c;
SetConsoleTextColor(12);
cout << setw(60) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(65) << "1.For encryption with shift 3." << endl;
cout << setw(65) << "2.For encryption with shift 7." << endl;
cout << setw(66) << "3.For encryption with shift 13." << endl;
cout << setw(76) << "4.For encryption with user defined shift." << endl;
SetConsoleTextColor(12);
cout << setw(54) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> c;
cout << endl;
switch (c)
{
case 1:
{
Cipher1 cipher1;
string text1 = cipher1.input();
string encrypted1 = cipher1.encrypt(text1);
SetConsoleTextColor(12);
cout << setw(66) << "Encrypted with Cipher_3: ";
SetConsoleTextColor(3);
cout << encrypted1 << endl;
break;
}
case 2:
{
Cipher2 cipher2;
string text2 = cipher2.input();
string encrypted2 = cipher2.encrypt(text2);
SetConsoleTextColor(12);
cout << setw(66) << "Encrypted with Cipher_7: ";
SetConsoleTextColor(3);
cout << encrypted2 << endl;
break;
}
case 3:
{
Cipher3 cipher3;
string text3 = cipher3.input();
string encrypted3 = cipher3.encrypt(text3);
SetConsoleTextColor(12);
cout << setw(67) << "Encrypted with Cipher_13: ";
SetConsoleTextColor(3);
cout << encrypted3 << endl;
break;
}
case 4:
{
int shift;
SetConsoleTextColor(12);
cout << setw(64) << "Enter the shift value: ";
SetConsoleTextColor(3);
cin >> shift;
CipherCustom cipherCustom(shift);
string textCustom = cipherCustom.input();
string encryptedCustom = cipherCustom.encrypt(textCustom);
SetConsoleTextColor(12);
cout << setw(63) << "Encrypted with Cipher_" << shift << ": ";
SetConsoleTextColor(3);
cout << encryptedCustom << endl;
break;
}
default:
{
cout << "Invalid Number! Please choose a correct number for
encryption." << endl;
break;
}
}
break;
}
case 2:
{
int d;
SetConsoleTextColor(12);
cout << setw(60) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(65) << "1.for decryption with shift 3." << endl;
cout << setw(65) << "2.for decryption with shift 7." << endl;
cout << setw(66) << "3.for decryption with shift 13." << endl;
cout << setw(76) << "4.for decryption with user defined shift." << endl;
SetConsoleTextColor(12);
cout << setw(54) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> d;
cout << endl;
switch (d)
{
case 1:
{
Cipher4 cipher4;
string text4 = cipher4.input();
string decrypted4 = cipher4.decrypt(text4, 3);
SetConsoleTextColor(12);
cout << setw(66) << "Decrypted with Cipher_3: ";
SetConsoleTextColor(3);
cout << decrypted4 << endl;
break;
}
case 2:
{
Cipher5 cipher5;
string text5 = cipher5.input();
SetConsoleTextColor(12);
string decrypted5 = cipher5.decrypt(text5, 7);
cout << setw(66) << "Decrypted with Cipher_7: ";
SetConsoleTextColor(3);
cout << decrypted5 << endl;
break;
}
case 3:
{
Cipher6 cipher6;
string text6 = cipher6.input();
string decrypted6 = cipher6.decrypt(text6, 13);
SetConsoleTextColor(12);
cout << setw(68) << "Decrypted with Cipher_13: ";
SetConsoleTextColor(3);
cout << decrypted6 << endl;
break;
}
case 4:
{
int shift;
SetConsoleTextColor(12);
cout << setw(64) << "Enter the shift value: ";
SetConsoleTextColor(3);
cin >> shift;
CipherCustomDecryption cipherCustomDecryption;
string textCustom = cipherCustomDecryption.input();
SetConsoleTextColor(12);
string decryptedCustom =
cipherCustomDecryption.decrypt(textCustom, shift);
cout << setw(63) << "Decrypted with Cipher_" << shift << ": ";
SetConsoleTextColor(3);
cout << decryptedCustom << endl;
break;
}
default:
{
SetConsoleTextColor(10);
cout << "Invalid Number! Please choose a correct number for
decryption." << endl;
break;
}
}
break;
}
default:
{
SetConsoleTextColor(10);
cout << "Invalid Number! Choose correct number for Ceasar
encryption/decryption." << endl;
break;
}
}
break;
}
case 2: //Substitutionl Cipher
{
map<char, char> substitutionMap =
{
{'a', 'q'}, {'b', 'w'}, {'c', 'e'}, {'d', 'r'}, {'e', 't'},
{'f', 'y'}, {'g', 'u'}, {'h', 'i'}, {'i', 'o'}, {'j', 'p'},
{'k', 'a'}, {'l', 's'}, {'m', 'd'}, {'n', 'f'}, {'o', 'g'},
{'p', 'h'}, {'q', 'j'}, {'r', 'k'}, {'s', 'l'}, {'t', 'z'},
{'u', 'x'}, {'v', 'c'}, {'w', 'v'}, {'x', 'b'}, {'y', 'n'},
{'z', 'm'}
};
SubstitutionCipher cipher(substitutionMap);
int e;
SetConsoleTextColor(12);
cout << setw(40) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(32) << "1.For encryption" << endl;
cout << setw(32) << "2.For decryption" << endl;
SetConsoleTextColor(12);
cout << setw(35) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> e;
cout << endl;
cin.ignore(); // ignore the newline character in the input buffer
string text;
if (e == 1)
{
SetConsoleTextColor(12);
cout << setw(49) << "Enter the text to encrypt: ";
SetConsoleTextColor(3);
getline(cin, text);
SetConsoleTextColor(12);
cout << setw(38) << "Encrypted text: ";
SetConsoleTextColor(3);
cout << cipher.encrypt(text) << endl;
}
else if (e == 2)
{
SetConsoleTextColor(12);
cout << setw(49) << "Enter the text to decrypt: ";
SetConsoleTextColor(3);
getline(cin, text);
SetConsoleTextColor(12);
cout << setw(38) << "Decrypted text: ";
SetConsoleTextColor(3);
cout << cipher.decrypt(text) << endl;
}
else
{
cout << "Invalid Number! Please choose a correct number for
Substitutional encryption/decryption.";
}
break;
}
case 3: // Reverse Cipher
{
int f;
SetConsoleTextColor(12);
cout << setw(40) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(32) << "1. For encryption" << endl;
cout << setw(32) << "2. For decryption" << endl;
SetConsoleTextColor(12);
cout << setw(35) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> f;
cin.ignore(); // Ignore newline character left in the buffer
cout << endl;
switch (f)
{
case 1:
{
ReverseCipherEncryption encryptor;
UserInput userInput;
string plainText = userInput.getInput("tttEnter text to encrypt: ");
string cipherText = encryptor.encrypt(plainText);
SetConsoleTextColor(12);
cout << setw(37) << "Cipher Text: ";
SetConsoleTextColor(3);
cout << cipherText << endl;
WriteToFile("encrypted.txt", cipherText);
break;
}
case 2:
{
ReverseCipherDecryption decryptor;
UserInput userInput;
string cipherText = userInput.getInput("tttEnter text to decrypt: ");
string plainText = decryptor.decrypt(cipherText);
SetConsoleTextColor(12);
cout << setw(37) << "Plain Text: ";
SetConsoleTextColor(3);
WriteToFile("decrypted.txt", plainText);
cout << plainText << endl;
WriteToFile("decrypted.txt", plainText);
break;
}
default:
{
SetConsoleTextColor(10);
cout << "Invalid Number! Choose correct number for Reverse
encryption/decryption." << endl;
break;
}
}
}
break;
case 4:
{
BaconCipher cipher;
string inputText;
int g;
SetConsoleTextColor(12);
cout << setw(40) << "Choose one of the below: " << endl;
SetConsoleTextColor(3);
cout << setw(32) << "1.for encryption" << endl;
cout << setw(32) << "2.for decryption" << endl;
SetConsoleTextColor(12);
cout << setw(35) << "Enter your choice: ";
SetConsoleTextColor(3);
cin >> g;
cout << endl;
cin.ignore();
switch (g)
{
case 1:
{
SetConsoleTextColor(12);
cout << setw(48) << "Enter the text to encode: ";
SetConsoleTextColor(3);
getline(cin, inputText);
string encodedText = cipher.encode(inputText);
SetConsoleTextColor(12);
cout << setw(36) << "Encoded Text: ";
SetConsoleTextColor(3);
cout << encodedText << endl;
break;
}
case 2:
{
SetConsoleTextColor(12);
cout << setw(48) << "Enter the text to decode: ";
SetConsoleTextColor(3);
getline(cin, inputText);
string decodedText = cipher.decode(inputText);
SetConsoleTextColor(12);
cout << setw(36) << "Decoded Text: ";
SetConsoleTextColor(3);
cout << decodedText << endl;
break;
}
default:
{
SetConsoleTextColor(10);
cout << "Invalid Number! Please choose a correct number bileteral for
encryption/decryption." << endl;
break;
}
}
break;
}
default:
{
SetConsoleTextColor(10);
cout << "Invalid Number! Choose correct number for
encryption/decryption of different Ciphers :)" << endl;
break;
}
}
cout << endl;
SetConsoleTextColor(6);
cout << "Do you want to run the program again? (y/n): ";
SetConsoleTextColor(6);
cin >> Z;
cout << endl;
SetConsoleTextColor(15);
} while (Z == 'Y' || Z == 'y');
SetConsoleTextColor(10);
cout << "Program Executed." << endl;
SetConsoleTextColor(15);
}
Output:
Selecting:
Picking shift:
Encrypting:
Decrypting:
Loop:
File Handling:
Encrypted Decrypted
We further have the plans to use file handling and for advance level. In which
complete files will get encrypted and decrypted respectively. Storing data in
new files and their encryption/decryption.
The End 😊

OOP project report cipher c++ .docx

  • 1.
    Department of ComputerSciences Bahria University, Islamabad Campus ` Object Oriented Programming Project Report Assignment # 4 (Project-Part II) This is a Group Assignment of maximum 3 students. Students can also work alone. Prepare Project Report including project description, features, source code, and screen shots of outcome and submit on time. Report should be properly formatted and should adhere to formal English.
  • 2.
    Contents Introduction:.............................................................................................................................. 3 Project Topic:......................................................................................................................... 3 Section:................................................................................................................................... 3 Group Members:..................................................................................................................... 3 Project Description ..................................................................................................................... 3 Intro:...................................................................................................................................... 3 Overview: ............................................................................................................................... 3 Features ..................................................................................................................................... 3 1. Caesar Cipher:................................................................................................................ 3 2. Substitution Cipher:........................................................................................................ 3 3. Reverse Cipher: .............................................................................................................. 4 4. Biliteral Cipher:.............................................................................................................. 4 Functionality: ............................................................................................................................. 4 Implementation Details:.............................................................................................................. 4 Classes:................................................................................................................................... 4 1.1 Caesar Cipher:............................................................................................................ 4 1.2 Subtitution Cipher: ..................................................................................................... 5 1.3 Reverse Cipher: .......................................................................................................... 5 1.4 Biliteral cipher: ........................................................................................................... 5 Source Code ............................................................................................................................... 5 Output: .....................................................................................................................................42 Selecting: ...............................................................................................................................42 Picking shift:..........................................................................................................................42 Encrypting:............................................................................................................................43 Decrypting:............................................................................................................................43 Loop:.....................................................................................................................................44 File Handling:........................................................................................................................44 Encrypted..............................................................................................................................44
  • 3.
    Introduction: Project Topic: Cryptic Vault:Encrypt/decrypt security secrets with Cryptography. Section: BS(CS)-2A Group Members: Abdul Wasay (01-134232-012). Muhammad Bilal (01-134232-115). Shafay Mirza (01-134232-131). Project Description Intro: Secure-Vault is an easy-to-use command-line tool for encrypting and decrypting messages with different ciphers, including custom formulas. It helps you protect sensitive information and decode encrypted messages simply and effectively. Overview: This project implements various classical ciphers in C++ including Caesar, Substitution, Reverse, Biliteral and Multiplicative ciphers. It allows users to encrypt and decrypt messages using different methods. Features 1. Caesar Cipher:  Provides encryption and decryption with shifts of 3, 7, 13, and custom user- defined shifts. 2. Substitution Cipher:  Uses a predefined substitution map for encryption and decryption of messages.
  • 4.
    3. Reverse Cipher: Encrypts text by reversing it and decrypts text by reversing the encrypted message. 4. Biliteral Cipher:  Encodes and decodes text using a mapping of characters to binary representations. Functionality:  Users can choose which cipher to use, whether to encrypt or decrypt, and the specific parameters (shifts, text inputs).  The program includes colorful console outputs for clarity and user interaction which has been done with the help of windows.h library.  The program has used iomanip library which helps the code to be in proper sequence.  The code also does file handling with the help of fstream library.  We have used map library which allows you to use the map container. A map is an associative container that stores elements in key-value pairs, where each key is unique. It provides efficient retrieval, insertion, and deletion operations based on keys.  The program runs in a loop, allowing users to perform multiple operations without restarting. Implementation Details: Classes: 1.1 Caesar Cipher:  CaesarCipher_encryption: Base class for Caesar cipher encryption.  Cipher1, Cipher2, Cipher3, CipherCustom: Subclasses of CaesarCipher_encryption with different shift values.  CaesarCipher_decryption: Base class for Caesar cipher decryption.
  • 5.
     Cipher4, Cipher5,Cipher6, CipherCustomDecryption: Subclasses of CaesarCipher_decryption for decryption with different shifts. 1.2 Subtitution Cipher:  SubstitutionCipher: Implements substitution cipher encryption and decryption. 1.3 Reverse Cipher:  ReverseCipherEncryption, ReverseCipherDecryption: Classes for reverse cipher encryption and decryption. 1.4 Biliteral cipher:  BaconCipher(Biliteral cipher): Implements Bacon cipher encoding and decoding. Source Code #include <iostream> #include <string> #include <fstream> #include <windows.h> #include <map> #include <algorithm> #include <iomanip> // Aligning #include <unordered_map> using namespace std; //***************************************************************** ****************************************************************** ************** // Parent Class
  • 6.
    class CaesarCipher_encryption { protected: int shift; public: CaesarCipher_encryption(ints) : shift(s % 26) {} void SetConsoleTextColor(int textColor) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, textColor); } string encrypt(const string& text) { string result = ""; for (char ch : text) { if (isupper(ch)) { result += char(int(ch + shift - 65) % 26 + 65); } else if (islower(ch)) { result += char(int(ch + shift - 97) % 26 + 97);
  • 7.
    } else { result += ch;// Non-alphabetic characters remain unchanged } } return result; } }; // Child class with shift 3 class Cipher1 : public CaesarCipher_encryption { public: Cipher1() : CaesarCipher_encryption(3) {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12);
  • 8.
    cout << setw(66)<< "Enter Text for Cipher 1: "; cin.ignore(); // Clear the buffer SetConsoleTextColor(3); getline(cin, text); return text; } }; // Child class with shift 7 class Cipher2 : public CaesarCipher_encryption { public: Cipher2() : CaesarCipher_encryption(7) {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(66) << "Enter Text for Cipher 2: "; SetConsoleTextColor(3);
  • 9.
    cin.ignore(); // Clearthe buffer getline(cin, text); return text; } }; // Child class with shift 13 class Cipher3 : public CaesarCipher_encryption { public: Cipher3() : CaesarCipher_encryption(13) {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(66) << "Enter Text for Cipher 3: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text);
  • 10.
    return text; } }; // Childclass with user-defined shift class CipherCustom : public CaesarCipher_encryption { public: CipherCustom(int shift) : CaesarCipher_encryption(shift) {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(71) << "Enter Text for Custom Cipher: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text); return text; }
  • 11.
    }; //***************************************************************** ****************************************************************** ************* class CaesarCipher_decryption { protected: int shift; public: voidSetConsoleTextColor(int textColor) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, textColor); } string decrypt(const string& a, int shift) { string result = a; for (char& c : result) { if (isalpha(c)) { char base = islower(c) ? 'a' : 'A'; c = (c - base - shift + 26) % 26 + base;
  • 12.
    } } return result; } }; class Cipher4: public CaesarCipher_decryption { public: Cipher4() : CaesarCipher_decryption() {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(66) << "Enter Text for Cipher_3: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text); return text;
  • 13.
    } }; class Cipher5 :public CaesarCipher_decryption { public: Cipher5() : CaesarCipher_decryption() {} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(66) << "Enter Text for Cipher_7: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text); return text; } }; class Cipher6 : public CaesarCipher_decryption
  • 14.
    { public: Cipher6() : CaesarCipher_decryption(){} void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(67) << "Enter Text for Cipher_13: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text); return text; } }; class CipherCustomDecryption : public CaesarCipher_decryption { public: CipherCustomDecryption() : CaesarCipher_decryption() {}
  • 15.
    void SetCursorPosition(int x,int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD position = { static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } string input() { string text; SetConsoleTextColor(12); cout << setw(75) << "Enter Text for Custom Decryption: "; SetConsoleTextColor(3); cin.ignore(); // Clear the buffer getline(cin, text); return text; } }; //***************************************************************** ****************************************************************** ************** //Substitution cipher class SubstitutionCipher { public:
  • 16.
    map<char, char> encryptionMap; map<char,char> decryptionMap; SubstitutionCipher(map<char, char> map) { encryptionMap = map; for (const auto& pair : map) decryptionMap[pair.second] = pair.first; } string encrypt(const string& plaintext) { string ciphertext; for (char c : plaintext) { if (encryptionMap.find(c) != encryptionMap.end()) { ciphertext += encryptionMap[c]; } else { ciphertext += c; // keep non-alphabetic characters unchanged } } return ciphertext;
  • 17.
    } string decrypt(const string&ciphertext) { string decryptedText; for (char c : ciphertext) { if (decryptionMap.find(c) != decryptionMap.end()) { decryptedText += decryptionMap[c]; } else { decryptedText += c; // keep non-alphabetic characters unchanged } } return decryptedText; } }; //***************************************************************** ****************************************************************** ************** //Reverse Cipher class ReverseCipherDecryption; // Forward declaration
  • 18.
    class ReverseCipherEncryption { public: string encrypt(conststring& plainText) { string cipherText = plainText; reverse(cipherText.begin(), cipherText.end()); return cipherText; } }; class ReverseCipherDecryption { public: string decrypt(const string& cipherText) { string plainText = cipherText; reverse(plainText.begin(), plainText.end()); return plainText; } friend string decryptUsingFriend(const ReverseCipherDecryption& dec, const string& cipherText); }; class UserInput
  • 19.
    { public: void SetConsoleTextColor(int textColor) { HANDLEhConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, textColor); } string getInput(const string& prompt) { string input; SetConsoleTextColor(12); cout << prompt; SetConsoleTextColor(3); getline(cin, input); return input; } }; void SetConsoleTextColor(int color) { // Function to set console text color for Windows HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, color); }
  • 20.
    void WriteToFile(const string&filename, const string& encryptedText) { ofstream outFile(filename, ios::binary); // Open file in binary mode if (outFile.is_open()) { outFile.write(encryptedText.c_str(), encryptedText.size()); outFile.close(); } else { cout << "Unable to open file: " << filename << endl; } } string ReadFromFile(const string& filename) { string encryptedText; ifstream inFile(filename, ios::binary); // Open file in binary mode if (inFile.is_open()) { inFile.seekg(0, ios::end); int fileSize = inFile.tellg(); inFile.seekg(0, ios::beg);
  • 21.
    char* buffer =new char[fileSize]; inFile.read(buffer, fileSize); encryptedText.assign(buffer, fileSize); delete[] buffer; inFile.close(); } else { cout << "Unable to open file: " << filename << endl; } return encryptedText; } string decryptUsingFriend(const ReverseCipherDecryption& dec, const string& cipherText) { string plainText = cipherText; reverse(plainText.begin(), plainText.end()); return plainText; } // Function to set cursor position void SetCursorPosition(int x, int y) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  • 22.
    COORD position ={ static_cast<SHORT>(x), static_cast<SHORT>(y) }; SetConsoleCursorPosition(hConsole, position); } //***************************************************************** ****************************************************************** ************* //Biliteral Cipher class BaconCipher { private: unordered_map<char, string> baconMap; unordered_map<string, char> reverseBaconMap; void initializeBaconCipher() { string baconCodes[26] = { "aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba", "aabbb", "abaaa", "abaab", "ababa", "ababb", "abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "babaa", "babab", "babba", "babbb", "bbaaa", "bbaab" }; for (char c = 'A'; c <= 'Z'; ++c) {
  • 23.
    baconMap[c] = baconCodes[c- 'A']; reverseBaconMap[baconCodes[c - 'A']] = c; } } public: BaconCipher() { initializeBaconCipher(); } string encode(const string& plaintext) { string encodedText; for (char c : plaintext) { if (isalpha(c)) { encodedText += baconMap[toupper(c)]; } } return encodedText; } string decode(const string& encodedText) {
  • 24.
    string decodedText; for (size_ti = 0; i < encodedText.size(); i += 5) { string segment = encodedText.substr(i, 5); if (reverseBaconMap.find(segment) != reverseBaconMap.end()) { decodedText += reverseBaconMap[segment]; } } return decodedText; } }; //***************************************************************** ****************************************************************** ************** int main() { const int colors[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; // Color names corresponding to the color codes
  • 25.
    const char* colorNames[]= { "Black", "Blue", "Green", "Aqua", "Red", "Purple", "Yellow", "White", "Gray", "Light Blue", "Light Green", "Light Aqua", "Light Red", "Light Purple", "Light Yellow", "Bright White" }; SetConsoleTextColor(2); cout << fixed << setw(85) << " Cryptic Vault" << endl << endl; cout << fixed << setw(93) << " Wellcome To Cipher World <3" << endl; char Z; do { int a; SetConsoleTextColor(12); cout << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << "1.Ceasar Cipher " << endl; cout << "2.Substitution Cipher " << endl; cout << "3.Reverse Cipher " << endl; cout << "4.Biliteral Cipher " << endl; SetConsoleTextColor(12); cout << "Enter your choice: "; SetConsoleTextColor(3); cin >> a;
  • 26.
    cout << endl; switch(a) { case 1: // Ceasar Cipher { int b; SetConsoleTextColor(12); cout << setw(40) << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << setw(32) << "1.For encryption" << endl; cout << setw(32) << "2.For decryption" << endl; SetConsoleTextColor(12); cout << setw(35) << "Enter your choice: "; SetConsoleTextColor(3); cin >> b; cout << endl; switch (b) { case 1: { int c; SetConsoleTextColor(12); cout << setw(60) << "Choose one of the below: " << endl;
  • 27.
    SetConsoleTextColor(3); cout << setw(65)<< "1.For encryption with shift 3." << endl; cout << setw(65) << "2.For encryption with shift 7." << endl; cout << setw(66) << "3.For encryption with shift 13." << endl; cout << setw(76) << "4.For encryption with user defined shift." << endl; SetConsoleTextColor(12); cout << setw(54) << "Enter your choice: "; SetConsoleTextColor(3); cin >> c; cout << endl; switch (c) { case 1: { Cipher1 cipher1; string text1 = cipher1.input(); string encrypted1 = cipher1.encrypt(text1); SetConsoleTextColor(12); cout << setw(66) << "Encrypted with Cipher_3: "; SetConsoleTextColor(3); cout << encrypted1 << endl; break; }
  • 28.
    case 2: { Cipher2 cipher2; stringtext2 = cipher2.input(); string encrypted2 = cipher2.encrypt(text2); SetConsoleTextColor(12); cout << setw(66) << "Encrypted with Cipher_7: "; SetConsoleTextColor(3); cout << encrypted2 << endl; break; } case 3: { Cipher3 cipher3; string text3 = cipher3.input(); string encrypted3 = cipher3.encrypt(text3); SetConsoleTextColor(12); cout << setw(67) << "Encrypted with Cipher_13: "; SetConsoleTextColor(3); cout << encrypted3 << endl; break; } case 4:
  • 29.
    { int shift; SetConsoleTextColor(12); cout <<setw(64) << "Enter the shift value: "; SetConsoleTextColor(3); cin >> shift; CipherCustom cipherCustom(shift); string textCustom = cipherCustom.input(); string encryptedCustom = cipherCustom.encrypt(textCustom); SetConsoleTextColor(12); cout << setw(63) << "Encrypted with Cipher_" << shift << ": "; SetConsoleTextColor(3); cout << encryptedCustom << endl; break; } default: { cout << "Invalid Number! Please choose a correct number for encryption." << endl; break; } } break;
  • 30.
    } case 2: { int d; SetConsoleTextColor(12); cout<< setw(60) << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << setw(65) << "1.for decryption with shift 3." << endl; cout << setw(65) << "2.for decryption with shift 7." << endl; cout << setw(66) << "3.for decryption with shift 13." << endl; cout << setw(76) << "4.for decryption with user defined shift." << endl; SetConsoleTextColor(12); cout << setw(54) << "Enter your choice: "; SetConsoleTextColor(3); cin >> d; cout << endl; switch (d) { case 1: { Cipher4 cipher4; string text4 = cipher4.input(); string decrypted4 = cipher4.decrypt(text4, 3);
  • 31.
    SetConsoleTextColor(12); cout << setw(66)<< "Decrypted with Cipher_3: "; SetConsoleTextColor(3); cout << decrypted4 << endl; break; } case 2: { Cipher5 cipher5; string text5 = cipher5.input(); SetConsoleTextColor(12); string decrypted5 = cipher5.decrypt(text5, 7); cout << setw(66) << "Decrypted with Cipher_7: "; SetConsoleTextColor(3); cout << decrypted5 << endl; break; } case 3: { Cipher6 cipher6; string text6 = cipher6.input(); string decrypted6 = cipher6.decrypt(text6, 13); SetConsoleTextColor(12);
  • 32.
    cout << setw(68)<< "Decrypted with Cipher_13: "; SetConsoleTextColor(3); cout << decrypted6 << endl; break; } case 4: { int shift; SetConsoleTextColor(12); cout << setw(64) << "Enter the shift value: "; SetConsoleTextColor(3); cin >> shift; CipherCustomDecryption cipherCustomDecryption; string textCustom = cipherCustomDecryption.input(); SetConsoleTextColor(12); string decryptedCustom = cipherCustomDecryption.decrypt(textCustom, shift); cout << setw(63) << "Decrypted with Cipher_" << shift << ": "; SetConsoleTextColor(3); cout << decryptedCustom << endl; break; } default:
  • 33.
    { SetConsoleTextColor(10); cout << "InvalidNumber! Please choose a correct number for decryption." << endl; break; } } break; } default: { SetConsoleTextColor(10); cout << "Invalid Number! Choose correct number for Ceasar encryption/decryption." << endl; break; } } break; } case 2: //Substitutionl Cipher { map<char, char> substitutionMap = {
  • 34.
    {'a', 'q'}, {'b','w'}, {'c', 'e'}, {'d', 'r'}, {'e', 't'}, {'f', 'y'}, {'g', 'u'}, {'h', 'i'}, {'i', 'o'}, {'j', 'p'}, {'k', 'a'}, {'l', 's'}, {'m', 'd'}, {'n', 'f'}, {'o', 'g'}, {'p', 'h'}, {'q', 'j'}, {'r', 'k'}, {'s', 'l'}, {'t', 'z'}, {'u', 'x'}, {'v', 'c'}, {'w', 'v'}, {'x', 'b'}, {'y', 'n'}, {'z', 'm'} }; SubstitutionCipher cipher(substitutionMap); int e; SetConsoleTextColor(12); cout << setw(40) << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << setw(32) << "1.For encryption" << endl; cout << setw(32) << "2.For decryption" << endl; SetConsoleTextColor(12); cout << setw(35) << "Enter your choice: "; SetConsoleTextColor(3); cin >> e; cout << endl; cin.ignore(); // ignore the newline character in the input buffer string text; if (e == 1) {
  • 35.
    SetConsoleTextColor(12); cout << setw(49)<< "Enter the text to encrypt: "; SetConsoleTextColor(3); getline(cin, text); SetConsoleTextColor(12); cout << setw(38) << "Encrypted text: "; SetConsoleTextColor(3); cout << cipher.encrypt(text) << endl; } else if (e == 2) { SetConsoleTextColor(12); cout << setw(49) << "Enter the text to decrypt: "; SetConsoleTextColor(3); getline(cin, text); SetConsoleTextColor(12); cout << setw(38) << "Decrypted text: "; SetConsoleTextColor(3); cout << cipher.decrypt(text) << endl; } else {
  • 36.
    cout << "InvalidNumber! Please choose a correct number for Substitutional encryption/decryption."; } break; } case 3: // Reverse Cipher { int f; SetConsoleTextColor(12); cout << setw(40) << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << setw(32) << "1. For encryption" << endl; cout << setw(32) << "2. For decryption" << endl; SetConsoleTextColor(12); cout << setw(35) << "Enter your choice: "; SetConsoleTextColor(3); cin >> f; cin.ignore(); // Ignore newline character left in the buffer cout << endl; switch (f) { case 1:
  • 37.
    { ReverseCipherEncryption encryptor; UserInput userInput; stringplainText = userInput.getInput("tttEnter text to encrypt: "); string cipherText = encryptor.encrypt(plainText); SetConsoleTextColor(12); cout << setw(37) << "Cipher Text: "; SetConsoleTextColor(3); cout << cipherText << endl; WriteToFile("encrypted.txt", cipherText); break; } case 2: { ReverseCipherDecryption decryptor; UserInput userInput; string cipherText = userInput.getInput("tttEnter text to decrypt: "); string plainText = decryptor.decrypt(cipherText); SetConsoleTextColor(12); cout << setw(37) << "Plain Text: "; SetConsoleTextColor(3); WriteToFile("decrypted.txt", plainText);
  • 38.
    cout << plainText<< endl; WriteToFile("decrypted.txt", plainText); break; } default: { SetConsoleTextColor(10); cout << "Invalid Number! Choose correct number for Reverse encryption/decryption." << endl; break; } } } break; case 4: { BaconCipher cipher; string inputText; int g; SetConsoleTextColor(12); cout << setw(40) << "Choose one of the below: " << endl; SetConsoleTextColor(3); cout << setw(32) << "1.for encryption" << endl;
  • 39.
    cout << setw(32)<< "2.for decryption" << endl; SetConsoleTextColor(12); cout << setw(35) << "Enter your choice: "; SetConsoleTextColor(3); cin >> g; cout << endl; cin.ignore(); switch (g) { case 1: { SetConsoleTextColor(12); cout << setw(48) << "Enter the text to encode: "; SetConsoleTextColor(3); getline(cin, inputText); string encodedText = cipher.encode(inputText); SetConsoleTextColor(12); cout << setw(36) << "Encoded Text: "; SetConsoleTextColor(3); cout << encodedText << endl; break; } case 2:
  • 40.
    { SetConsoleTextColor(12); cout << setw(48)<< "Enter the text to decode: "; SetConsoleTextColor(3); getline(cin, inputText); string decodedText = cipher.decode(inputText); SetConsoleTextColor(12); cout << setw(36) << "Decoded Text: "; SetConsoleTextColor(3); cout << decodedText << endl; break; } default: { SetConsoleTextColor(10); cout << "Invalid Number! Please choose a correct number bileteral for encryption/decryption." << endl; break; } } break; } default:
  • 41.
    { SetConsoleTextColor(10); cout << "InvalidNumber! Choose correct number for encryption/decryption of different Ciphers :)" << endl; break; } } cout << endl; SetConsoleTextColor(6); cout << "Do you want to run the program again? (y/n): "; SetConsoleTextColor(6); cin >> Z; cout << endl; SetConsoleTextColor(15); } while (Z == 'Y' || Z == 'y'); SetConsoleTextColor(10); cout << "Program Executed." << endl; SetConsoleTextColor(15); }
  • 42.
  • 43.
  • 44.
  • 45.
    We further havethe plans to use file handling and for advance level. In which complete files will get encrypted and decrypted respectively. Storing data in new files and their encryption/decryption. The End 😊