SlideShare a Scribd company logo
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 😊

More Related Content

PDF
3- In the program figurespointers we have a base class location and va.pdf
PDF
Mobile Email Security
PPTX
C programming language tutorial
PDF
Cypherock Assessment (1).pdf
PDF
c++ referesher 1.pdf
PDF
C,c++ interview q&a
PDF
Computer Project For Class XII Topic - The Snake Game
PPTX
Java Programming Tutorials Basic to Advanced 2
3- In the program figurespointers we have a base class location and va.pdf
Mobile Email Security
C programming language tutorial
Cypherock Assessment (1).pdf
c++ referesher 1.pdf
C,c++ interview q&a
Computer Project For Class XII Topic - The Snake Game
Java Programming Tutorials Basic to Advanced 2

Similar to OOP project report cipher c++ .docx (20)

PDF
0100_Embeded_C_CompilationProcess.pdf
PPTX
C Language ppt create by Anand & Sager.pptx
PDF
Data Structure and Algorithms (DSA) with Python
PPTX
C_Progragramming_language_Tutorial_ppt_f.pptx
PPTX
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
DOCX
Let's us c language (sabeel Bugti)
PPTX
PRINCE PRESENTATION(1).pptx
PPTX
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
DOCX
A project on advanced C language
DOCX
System programmin practical file
PPTX
The operation principles of PVS-Studio static code analyzer
PDF
Effective Object Oriented Design in Cpp
PPTX
Static code analysis: what? how? why?
PPTX
Next-generation sequencing data format and visualization with ngs.plot 2015
PPT
270 1 c_intro_up_to_functions
PPT
270_1_CIntro_Up_To_Functions.ppt
PPT
270_1_CIntro_Up_To_Functions.ppt
PPT
Survey of programming language getting started in C
PDF
100 bugs in Open Source C/C++ projects
0100_Embeded_C_CompilationProcess.pdf
C Language ppt create by Anand & Sager.pptx
Data Structure and Algorithms (DSA) with Python
C_Progragramming_language_Tutorial_ppt_f.pptx
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
Let's us c language (sabeel Bugti)
PRINCE PRESENTATION(1).pptx
UNIT - 1- Ood ddnwkjfnewcsdkjnjkfnskfn.pptx
A project on advanced C language
System programmin practical file
The operation principles of PVS-Studio static code analyzer
Effective Object Oriented Design in Cpp
Static code analysis: what? how? why?
Next-generation sequencing data format and visualization with ngs.plot 2015
270 1 c_intro_up_to_functions
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
Survey of programming language getting started in C
100 bugs in Open Source C/C++ projects
Ad

Recently uploaded (20)

PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Lesson notes of climatology university.
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Classroom Observation Tools for Teachers
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Complications of Minimal Access Surgery at WLH
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
What if we spent less time fighting change, and more time building what’s rig...
Lesson notes of climatology university.
Updated Idioms and Phrasal Verbs in English subject
Weekly quiz Compilation Jan -July 25.pdf
01-Introduction-to-Information-Management.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
LDMMIA Reiki Yoga Finals Review Spring Summer
Supply Chain Operations Speaking Notes -ICLT Program
Chinmaya Tiranga quiz Grand Finale.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Classroom Observation Tools for Teachers
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
Complications of Minimal Access Surgery at WLH
Ad

OOP project report cipher c++ .docx

  • 1. 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.
  • 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(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);
  • 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(); // 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);
  • 10. 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; }
  • 11. }; //***************************************************************** ****************************************************************** ************* 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;
  • 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(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
  • 19. { 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); }
  • 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_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
  • 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; 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:
  • 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 << "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 = {
  • 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 << "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:
  • 37. { 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);
  • 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 << "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); }
  • 45. 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 😊