-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp-cipher.cpp
More file actions
203 lines (148 loc) · 4.91 KB
/
cpp-cipher.cpp
File metadata and controls
203 lines (148 loc) · 4.91 KB
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
#include <iostream>
#include <stdlib.h>
using namespace std;
#define BOLD_BLACK "\033[1;30m"
#define BOLD_RED "\033[1;31m"
#define BOLD_GREEN "\033[1;32m"
#define BOLD_YELLOW "\033[1;33m"
#define BOLD_BLUE "\033[1;34m"
#define BOLD_MAGENTA "\033[1;35m"
#define BOLD_CYAN "\033[1;36m"
#define BOLD_WHITE "\033[1;37m"
#define RESET "\033[0m"
/*
Author : William Steven \n;
Definition : Classic ceaser cypher tool \n;
Note : Fork kor korle || copy korle tor মারে চুদি 🖕\n;
*/
void banner() {
cout << BOLD_CYAN << "\n\n _ __ \n";
cout << " _________ ____ _____(_)___ / /_ ___ _____ \n";
cout << " / ___/ __ \\/ __ \\______/ ___/ / __ \\/ __ \\/ _ \\/ ___/ \n";
cout << "/ /__/ /_/ / /_/ /_____/ /__/ / /_/ / / / / __/ / \n";
cout << "\\___/ .___/ .___/ \\___/_/ .___/_/ /_/\\___/_/ \n";
cout << " /_/ /_/ /_/ \n\n\n" << RESET;
}
int encryption(string sentence) {
int shift;
cout << BOLD_WHITE << "Enter shift number: ";
cin >> shift;
cout << BOLD_CYAN << "\nCipher text : ";
for (char c : sentence) {
if (c >= 'A' && c <= 'Z') {
c = ((c - 'A' + shift) % 26) + 'A';
cout << c;
}
else if (c >= 'a' && c <= 'z') {
c = ((c - 'a' + shift) % 26) + 'a';
cout << c;
}
else {
cout << c;
}
}
cout << RESET << "\n";
return 0;
}
int decryption(string sentence){
int shift;
cout<< BOLD_GREEN <<"\n1) Custom shift number\n2) Test all (default)\n" << RESET <<endl;
int choice;
cout<< BOLD_WHITE << "Enter decryption mathod number : ";
cin>> choice;
if (choice== 1) {
int num;
cout << BOLD_WHITE << "Enter shift number: ";
cin >> num;
cout << "\n";
cout << BOLD_CYAN << "Plain text: ";
for (char c : sentence) {
if (c >= 'A' && c <= 'Z') {
c = ((c - 'A' - num + 26) % 26) + 'A';
cout << c;
} else if (c >= 'a' && c <= 'z') {
c = ((c - 'a' - num + 26) % 26) + 'a';
cout << c;
} else {
cout << c;
}
}
cout << BOLD_BLUE << " (Shift " << num << ")\n" << RESET;
}else if(choice== 2){
cout<< "\n";
int x = 1;
for(shift = 25 ; shift > 0 ; shift--){
cout << BOLD_CYAN << "Plain text : ";
for (char c : sentence) {
if (c >= 'A' && c <= 'Z') {
c = ((c - 'A' + shift) % 26) + 'A';
cout << c;
}
else if (c >= 'a' && c <= 'z') {
c = ((c - 'a' + shift) % 26) + 'a';
cout << c;
}
else {
cout << c;
}
}
cout << BOLD_BLUE << " ( Shift " << x << " )";
cout << RESET << "\n";
x++;
}
}else {
cout << BOLD_RED << "Invalid option." << RESET << endl;
}
return 0;
}
int main() {
system("clear");
int opt;
bool runAgain = true;
while (runAgain) {
banner();
cout << BOLD_GREEN << "1) Encryption" << endl << "2) Decryption" << RESET << endl;
cout << BOLD_WHITE << "\nOption number : ";
cin >> opt;
if (opt == 1) {
system("clear");
banner();
string text;
cout << BOLD_WHITE << "Enter your text here : ";
cin.ignore();
getline(cin, text);
encryption(text);
} else if (opt == 2) {
system("clear");
banner();
string text;
cout << BOLD_WHITE << "Enter encrypted text here : ";
cin.ignore();
getline(cin, text);
decryption(text);
} else {
cout << BOLD_RED << "Wrong option" << RESET << endl;
continue;
}
int YorN;
cout << BOLD_YELLOW << "\nDo you want to use this script one more time ??\n"
<< BOLD_GREEN << "\n1) Yes\n2) No\n" << RESET;
cout << BOLD_WHITE << "\nEnter the value of yes or no (1/2) : ";
cin >> YorN;
if (YorN == 1) {
runAgain = true;
system("clear");
} else if (YorN == 2) {
cout << BOLD_GREEN << "\nGood bye 👋\nExiting !" << RESET <<endl;
runAgain = false;
} else {
cout << BOLD_RED << "Unknown option\nExiting !" << RESET << endl;
runAgain = false;
}
}
return 0;
}
/*
last message : বাহ চুদির ভাই 🙂
তুই তাও copy করবি ??
*/