-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
277 lines (223 loc) · 6.52 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//bl4ckbo7 CRYPTOSYSTEM (With (Encryption + Decryption) functions)
//Coded by bl4ckbo7
//February 1, 2017
#include <iostream>
#include <string>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
using namespace std;
//encrypting function(Encrypts the plaintext)
string encode(string plaintext, int shift){
string ciphertext;
string encode_engine(string plaintext, int shift);
//prompts the user to enter the plaintext
cout<<"Please enter the plaintext: \n\n";
cin>>plaintext;
//open output stream that prints the output in the file
ofstream fout("EncodeFile.txt");
//prompts the user to enter the key to encrypt the plaintext
cout<< "\nWhat is your key? ";
cin>>shift;
cout<<"\n\n";
//checks if the key is greater than one unless it repeats the loop
while (shift < 1) {
cout<< "You have entered an invalid number. \n";
cout<< "Please try again. \n";
cout<< "Enter a proper number for the amount of letter shifting: ";
cin>>shift;
}
//display/alerts the user that the program is encrypting the plaintext
cout<<"Encrypting....\n\n";
//assigns ciphertext the value in encode function
ciphertext = encode_engine(plaintext, shift);
//outputs the ciphertext on the screen
cout<<"\nEncoded message: \a\n\n" << ciphertext << "\n\n";
//outputs the values in the output file
fout<<"\tCAESAR CIPHER CRYPTO\n";
fout<<"\tDEVELOPED BY ANDY KAWA - BL4CKBO7\n";
fout<<"\t (c) 2017\n\n";
fout<<"Your plaintext >>>\n";
fout<<plaintext<<"\n\n";
fout<<"Key used >>>\n";
fout<<shift<<"\n\n";
fout<<"Your Ciphertext >>>\n";
fout<<ciphertext<<"\n\n";
//closes the output stream
fout.close();
system("pause");
return ciphertext;
}
//Plaintext encrypting engine
string encode_engine(string plaintext, int shift){
string temp = plaintext;
int length;
length = temp.length();
//increments the size of string until the exact one entered by the user
for (int i = 0; i < length; i++)
{
//validates that each characters in the string is a letter
if (isalpha(temp[i]))
{
for (int j = 0; j < shift; j++)
{
if (temp[i] == 'z')
{
temp[i] = 'a';
}
else if (temp[i] == 'Z')
{
temp[i] = 'A';
}
else
{
temp[i]++;
}
}
}
}
return temp;
}
//Decrypting function (Decrypts the ciphertext)
string decode(string ciphertext, int shift){
string plaintext;
string decode_engine(string ciphertext, int shift);
//prompts the user to enter the ciphertext
cout<<"Please enter the ciphertext: \n\n";
cin>>ciphertext;
//prompts the user to enter the key to decrypt the plaintext
cout<< "\nWhat is your key? ";
cin>>shift;
cout<<"\n\n";
//checks if the key is greater than one unless it requests user to re-enter key
while (shift < 1) {
cout<< "You have entered an invalid number. \n";
cout<< "Please try again. \n";
cout<< "Enter a proper number for the amount of letter shifting: ";
cin>>shift;
}
//display/alerts the user that the program is decrypting the ciphertext
cout<<"Decrypting....\n\n";
//assigns plaintext the value in decode engine
plaintext = decode_engine(ciphertext, shift);
//outputs the plaintext on the screen
cout<<"\nPlaintext Found! >>>>> \a \x5B " << plaintext << " \x5D\n\n";
system("pause");
return plaintext;
}
//Ciphertext decrypting engine
string decode_engine(string ciphertext, int shift){
string temp2 = ciphertext;
int length;
length = temp2.length();
//increments the size of string until the exact one entered by the user
for (int i = 0; i < length; i++)
{
//validates that each characters in the string is a letter
if (isalpha(temp2[i]))
{
for (int j = 26; j > shift; j--)
{
if (temp2[i] == 'z')
{
temp2[i] = 'a';
}
else if (temp2[i] == 'Z')
{
temp2[i] = 'A';
}
else
{
temp2[i]++;
}
}
}
}
return temp2;
}
//about program function
void about(){
cout<<"\n\n\tbl4ckbo7 CIPHER CRYPTO\n\n";
cout<<"\tDEVELOPED BY ANDY KAWA - bl4ckbo7@protonmail.com\n\n";
cout<<"\t \x40 2017\n\n";
}
//function menu of user choices
void menu(){
cout<<"\t***CRYPTO MENU***\n\n";
cout<<"\t1. Encryption\n\n";
cout<<"\t2. Decryption\n\n";
cout<<"\t3. About\n\n";
}
//function to quit the program
int quit(){
char Quit;
int main();
cout<<"\nYou wanna quit (Y/n)?\n";
cin>>Quit;
if (Quit == 'Y'){
system("cls");
cout<<"Goodbye! \n\n";
system ("exit");
}
else if(Quit == 'n'){
system("cls");
cout<<main();
}
else{
system("cls");
cout<<"Wrong choice! \n\n";
system("pause");
system("cls");
cout<<quit();
}
return 0;
}
//declaration of the functions and their respective variables
string encode_engine(string plaintext, int shift);
string decode_engine(string ciphertext, int shift);
string encode(string plaintext, int shift);
string decode(string ciphertext, int shift);
//main function starts - the core of the cipher program
int main(){
system("color 0a");
string plaintext, ciphertext;
int shift = 0;
string encode_;
string decode_;
int choice;
int abt;
int quit();
int about();
int menu();
cout << "\n******/*****************[ Welcome to bl4ckbo7 Cipher ]*****************/******\n\n";
cout<<"----------------------DEVELOPED BY ANDY KAWA CYBER-LABS-------------------------\n\n\n";
do {
//displays the menu of the program
choice = menu();
cout<<"\n\n";
cin>>choice;
}
while (choice < 1 || choice > 3);
//if conditions options
if (choice == 1){
cout<<"\n********[ ---ENCODE--- ]*******\n";
encode_ = encode(plaintext, shift);
cout<<quit();
}
else if (choice == 2){
cout<<"\n********[ ---DECODE--- ]*******\n";
decode_ = decode(ciphertext, shift);
cout<<quit();
}
else if (choice == 3) {
cout<<"\n********[ ---ABOUT--- ]*******\n";
abt = about();
cout<<quit();
}
else{
cout<<"Wrong choice! Please Repeat again!";
cout<<main();
}
getch();
}