-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCiphersApp.cpp
851 lines (744 loc) · 23.2 KB
/
CiphersApp.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/**
FCAI - Programming 1 - 2022 - Assignment 2
Program Name: All Ciphers.cpp
Program Description: Encrypt and decrypt messages using any of the ten ciphers
Last Modification Date: 23/3/2022
Author Name: Khaled Salah
Purpose: Practicing c++
*/
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
string option;
void AffineCipher(int a, int b) {
string s, ns;
cout << "Enter your massage :\n";
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
if (static_cast<char>(towlower(s[i])) > 122 || static_cast<char>(towlower(s[i])) < 97) {
ns[i] = static_cast<char>(towlower(s[i]));
} else {
ns[i] = char((((a * (towlower(s[i]) - 97) + b) % 26 + 26) % 26) + 97);
}
}
cout << "Your massage after encryption is: " << ns << endl;
}
void AffineDecipher(int b, int c) {
string s, ns;
cout << "Enter your massage : \n";
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
if (static_cast<char>(towlower(s[i])) > 122 || (towlower(s[i]) < 97)) { ns[i] = (char) towlower(s[i]); }
else {
ns[i] = char(((c * (tolower(s[i]) - 97) - b) % 26 + 26) % 26 + 97);
}
}
cout << "Your massage after decryption is: " << ns << endl;
}
void Affine() {
int a = 5, b = 8, c = 21;
int n;
while (true) {
cout
<< "Welcome to Affine cipher. \n What do you like to do today? \n 1- Cipher a message \n 2- Decipher a message \n 3- Change the cipher and decipher constants a,b and c \n type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { AffineCipher(a, b); }
else if (n == 2) { AffineDecipher(b, c); }
else if (n == 3) {
cout
<< "Enter a,b and c constants space-separated, cipher formula is (a x+ b)%26 and decipher formula is c*(y - b)%26 : "
<< endl;
while (true) {
cin >> a >> b >> c;
if ((a * c) % 26 == 1) break;
cout
<< "Non valid numbers please enter a,b and c constants again satisfying the condition (a * c) mod 26 = 1 :\n";
}
} else { return; }
}
}
int shift(int x, int a) {
if (x < 123 && (x + a) > 122) return x + a - 26;
else return (x + a);
}
int ShiftBack(int x, int a) {
if (x > 96 && (x - a) < 97) return x - a + 26;
else return x - a;
}
void CaesarCipher(int a) {
string s, ns;
cout << "Enter your massage :\n";
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
if (towlower(s[i]) > 122 || towlower(s[i]) < 97) { ns[i] = s[i]; }
else {
ns[i] = char(shift(towlower(s[i]) - 0, a));
}
}
cout << "Your massage after encryption is: " << ns << endl;
}
void CaesarDecipher(int a) {
string s, ns;
cout << "Enter your massage : \n";
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
if (towlower(s[i]) - 0 > 122 || towlower(s[i]) - 0 < 97) { ns[i] = s[i]; }
else {
ns[i] = char(ShiftBack(towlower(s[i]) - 0, a));
}
}
cout << "Your massage after decryption is: " << ns << endl;
}
void Caesar() {
int a;
int n;
while (true) {
cout << "Welcome to Caesar cipher.\n"
"Enter a constant 'a' that indicates how many times every letter will be shifted: " << endl;
cin >> option;
a = option[0] - 48;
if (a < 27) {
break;
}
cout << "Invalid number. Please enter a constant again satisfying the condition (a < 27):" << endl;
}
while (true) {
cout << "What would you like to do today?\n"
"1 - Cipher a message\n"
"2 - Decipher a message\n"
"Type anything else to go to the main menu of ciphers:" << endl;
cin >> option;
n = option[0] - 48;
if (n == 1) {
CaesarCipher(a);
} else if (n == 2) {
CaesarDecipher(a);
} else {
return;
}
}
}
void AtbashCipher(int x) {
string s, ns;
cout << "Enter your message: " << endl;
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
if ((towlower(s[i]) - 0) > 122 || (towlower(s[i]) - 0) < 97) {
ns[i] = char((s[i]));
} else {
ns[i] = char(towlower(s[i]) + 219 - 2 * towlower(s[i]));
}
}
if (x) {
cout << "Your message after encryption is: " << ns << endl;
} else {
cout << "Your message after decryption is: " << ns << endl;
}
}
void Atbash() {
int n;
while (true) {
cout << "Welcome to Atbash Cipher. What do you want to do?\n"
"1 - Perform encryption\n"
"2 - Perform decryption\n"
"* Type anything else to go to the main menu of ciphers." << endl;
cin >> option;
n = option[0] - 48;
if (n == 1) {
AtbashCipher(1);
} else if (n == 2) {
AtbashCipher(0);
} else {
return;
}
}
}
void VignereDecipher(string s2) {
string s, ns;
cout << "Enter the massage to be Decrypted :" << endl;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() < 81) break;
cout << "Too many characters , try again with maximum 80 characters : " << endl;
}
ns = s;
for (char &i: s2) {
i = (char) toupper(i);
}
for (int i = 0; i < s.size(); i++) {
if ((towlower(s[i]) - 0) > 122 || (towlower(s[i]) - 0) < 97) { ns[i] = char(s[i]); }
else {
int a = 0;
if ((toupper(s[i]) - 0) < (toupper(s2[i - (s2.size() * ((int) (i / s2.size())))]) - 0)) { a = 26; }
ns[i] = char(((toupper(s[i]) + a) - toupper(s2[i - (s2.size() * ((int) (i / s2.size())))])) + 65);
}
}
cout << "Your massage after Decryption is: " << ns << endl;
}
void VignereCipher(string s2) {
string s, ns;
cout << "Enter the massage to be encrypted :" << endl;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() < 81) break;
cout << "Too many characters , try again with maximum 80 characters : " << endl;
}
ns = s;
for (char &i: s2) { i = (char) toupper(i); }
for (int i = 0; i < s.size(); i++) {
if ((towlower(s[i]) - 0) > 122 || (towlower(s[i]) - 0) < 97) { ns[i] = char(s[i]); }
else {
ns[i] = char(((toupper(s[i]) + toupper(s2[i - (s2.size() * ((int) (i / s2.size())))])) % 26) + 65);
}
}
cout << "Your massage after encryption is: " << ns << endl;
}
void Vignere() {
int n;
string s;
cout << "Welcome in VignereCipher, enter the keyword of encryption :" << endl;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() < 9) break;
cout << "Too many characters , try again with maximum 8 characters : " << endl;
}
while (true) {
cout
<< "What do you want to do? \n 1- do encryption \n 2- do Decryption \n *type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { VignereCipher(s); }
else if (n == 2) { VignereDecipher(s); }
else { return; }
}
}
void SimpleSubstitutionDecipher(const char key[26]) {
string s, ns;
cout << "Enter the massage to be Decrypted :" << endl;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() < 81) break;
cout << "Too many characters , try again with maximum 80 characters : " << endl;
}
ns = s;
for (int i = 0; i < s.size(); i++) {
if ((towlower(s[i]) - 0) > 122 || (towlower(s[i]) - 0) < 97) { ns[i] = char(s[i]); }
else {
ns[i] = char(key[tolower(s[i]) - 97] + 97);
}
}
cout << "Your massage after Decryption is: " << ns << endl;
}
void SimpleSubstitutionCipher(const char key[26]) {
string s, ns;
cout << "Enter the massage to be encrypted :" << endl;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() < 81) break;
cout << "Too many characters , try again with maximum 80 characters : " << endl;
}
ns = s;
for (int i = 0; i < s.size(); i++) {
if ((towlower(s[i]) - 0) > 122 || (towlower(s[i]) - 0) < 97) { ns[i] = char(s[i]); }
else {
ns[i] = key[towlower(s[i]) - 97];
}
}
cout << "Your massage after encryption is: " << ns << endl;
}
void SimpleSubstitution() {
pair<char, bool> arr[26];
for (int i = 0; i < 26; i++) {
arr[i].first = char(97 + i);
arr[i].second = false;
}
char key[26];
char key2[26];
int n;
cout << "Welcome SimpleSubstitutionCipher, enter the keyword of encryption consisting of 5 characters :" << endl;
string s;
while (true) {
cin.clear();
cin.sync();
getline(cin, s);
if (s.size() == 5) break;
cout << "Non-valid number of characters , try again with exactly 5 characters : " << endl;
}
for (int i = 0; i < 5; i++) {
key[i] = (char) towlower(s[i]);
arr[(tolower(s[i]) - 97)].second = true;
key2[towlower(s[i]) - 97] = (char) i;
}
int a = 5;
for (int i = 0; i < 26; i++) {
if (arr[i].second) {
a--;
continue;
}
key[i + a] = arr[i].first;
key2[arr[i].first - 97] = (char) (i + a);
}
while (true) {
cout
<< "What do you want to do? \n 1- do encryption \n 2- do Decryption \n *type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { SimpleSubstitutionCipher(key); }
else if (n == 2) { SimpleSubstitutionDecipher(key2); }
else { return; }
}
}
void BaconianDecipher() {
string s, ns;
cout << "Enter the massage to be Decrypted, note it should be only a combination of a and b :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
ns = "";
for (int a = 0; a < s.size(); a += 6) {
if (!(s[a] == 'b' || s[a] == 'a')) {
ns += s[a];
a -= 5;
} else {
int x = 0;
for (int i = 0; i < 5; i++) { if (s[i + a] == 'b') x += (int) pow(2, 4 - i); }
ns += char(x + 97);
}
}
cout << "Your massage after Decryption is: " << ns << endl;
}
void BaconianCipher() {
string s, ns, x;
cout << "enter the massage to be encrypted :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
for (char i: s) {
if ((towlower(i) - 0) > 122 || (towlower(i) - 0) < 97) { ns += i; }
else {
x = "12345";
for (int d = 4; d >= 0; d--) {
int a = ((towlower(i) - 97) >> d);
if (a & 1) { x[4 - d] = 'b'; }
else { x[4 - d] = 'a'; }
}
ns += x + ' ';
}
}
cout << "Your massage after encryption is: " << ns << endl;
}
void Baconian() {
int n;
while (true) {
cout
<< "Welcome to BaconianCipher, what do you want to do? \n 1- do encryption \n 2- do Decryption \n *type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { BaconianCipher(); }
else if (n == 2) { BaconianDecipher(); }
else { return; }
}
}
// This function deciphers a message using the Polybius Square Cipher
void PolybiusSquareDecipher(char arr[10][10]) {
string s, ns; // s is the original message, ns is the deciphered message
cout << "Enter the massage to be Decrypted :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
// Iterate through each character of the original message
for (int i = 0; i < s.size(); i += 2) {
// If the character is not a number, add it to the deciphered message
if ((s[i] - 0) > 58 || (s[i] - 0) < 49) {
ns += s[i];
i--;
}
// Otherwise, use the Polybius Square Cipher to decipher the character
else {
ns += arr[s[i] - 48][s[i + 1] - 48];
}
}
cout << " your massage after Decryption is: " << ns << endl;
}
// This function encrypts a message using the Polybius Square Cipher
void PolybiusSquareCipher(int arr[26]) {
string s, ns; // s is the original message, ns is the encrypted message
cout << "Enter the massage to be encrypted :" << endl;
cin.clear();
cin.sync();
getline(cin, s); // Get the message from the user
for (char i: s) { // Iterate through each character in the message
if ((towlower(i) - 0) > 122 || (towlower(i) - 0) < 97) {
// If the character is not a letter, add it to the encrypted message
ns += i;
} else {
// Otherwise, add the corresponding number from the array to the encrypted message
ns += to_string(arr[toupper(i) - 65]);
}
}
cout << " your massage after encryption is: " << ns << endl;
}
void PolybiusSquare() {
// Declare a 10x10 array to store the Polybius Square
char arr[10][10];
// Declare an array to store the reference of the Polybius Square
int ref[26];
// Declare a variable to store user input
int n;
// Ask the user to enter a keyword of 5 characters
cout << "Welcome to SimpleSubstitutionCipher, enter the keyword of encryption consisting of 5 characters :" << endl;
string s;
while (true) {
cin >> s;
if (s.size() == 5) break;
cout << "Non-valid number of characters, try again with exactly 5 characters : " << endl;
}
// Create the Polybius Square and the reference array
for (int a = 0; a < 5; a++) {
for (int i = 0; i < 5; i++) {
arr[s[a] - 48][s[i] - 48] = char(65 + 5 * a + i);
ref[5 * a + i] = (10 * (s[a] - 48)) + (s[i] - 48);
}
}
// Ask the user what they want to do
while (true) {
cout << "What do you want to do? \n"
" 1- do encryption \n"
" 2- do Decryption \n"
" *type any other thing to go to ciphers main menu " << endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { PolybiusSquareCipher(ref); }
else if (n == 2) { PolybiusSquareDecipher(arr); }
else { return; }
}
}
void MorseCodeDecipher(map<string, char> key) {
string s, ns;
cout << "Enter the massage to be Decrypted :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
string x;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ' ') {
ns += key[x];
if (s[i + 1] == ' ') {
ns += ' ';
i += 2;
}
x = "";
continue;
}
x += s[i];
}
ns += key[x];
cout << "Your massage after Decryption is: " << ns << endl;
}
void MorseCodeCipher(map<char, string> key) {
// Declare variables
string s, ns;
// Prompt user for message to be encrypted
cout << "Enter the message to be encrypted: " << endl;
cin.clear();
cin.sync();
getline(cin, s);
// Loop through characters in message
for (char i: s) {
// Check if character is a letter or not
if ((towlower(i) - 0) > 122 || (towlower(i) - 0) < 97) {
// If not a letter, add corresponding morse code to new string
ns += key[i] + ' ';
} else {
// If letter, convert to uppercase and add corresponding morse code to new string
ns += key[(char) toupper(i)] + ' ';
}
}
// Print encrypted message
cout << "Your message after encryption is: " << ns << endl;
}
void MorseCode() {
int n;
// Create map of characters and their corresponding morse code
map<char, string> key1 = {
{' ', " "},
{',', "--..--"},
{'.', ".-.-.-"},
{'?', "..--.."},
{'0', "-----"},
{'1', ".----"},
{'2', "..---"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{'9', "----."},
{'A', ".-"},
{'B', "-..."},
{'C', "-.-."},
{'D', "-.."},
{'E', "."},
{'F', "..-."},
{'G', "--."},
{'H', "...."},
{'I', ".."},
{'J', ".---"},
{'K', "-.-"},
{'L', ".-.."},
{'M', "--"},
{'N', "-."},
{'O', "---"},
{'P', ".--."},
{'Q', "--.-"},
{'R', ".-."},
{'S', "..."},
{'T', "-"},
{'U', "..-"},
{'V', "...-"},
{'W', ".--"},
{'X', "-..-"},
{'Y', "-.--"},
{'Z', "--.."},
};
// Create map of morse code and their corresponding characters
map<string, char> key2;
key2["--..--"] = ',';
key2[" "] = ' ';
key2[".-.-.-"] = '.';
key2["..--.."] = '?';
for (int i = 0; i < (10); i++) {
key2[key1[char(i + 48)]] = char(i + 48);
}
for (int i = 0; i < (26); i++) {
key2[key1[char(i + 65)]] = char(i + 65);
}
// Prompt user for action
while (true) {
cout
<< "Welcome to MorseCode, what do you want to do? \n 1- do encryption \n 2- do Decryption \n *type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
// Call cipher or decipher function based on user input
if (n == 1) { MorseCodeCipher(key1); }
else if (n == 2) { MorseCodeDecipher(key2); }
else { return; }
}
}
void XORDecipher(int k) {
string s, ns;
cout << "enter the massage to be Decrypted ( in hexadecimal ) :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
for (int i = 0; i < s.size() - 1; i += 2) {
string y;
y += s[i];
y += s[i + 1];
int x = stoi(y, nullptr, 16);
x ^= k;
ns += char(x);
}
cout << " your massage after Decryption is: " << ns << endl;
}
void XORCipher(int k) {
string s, ns;
cout << "enter the massage to be encrypted :" << endl;
cin.clear();
cin.sync();
getline(cin, s);
ns = s;
for (int i = 0; i < s.size(); i++) {
int x = toupper(s[i]) - 0;
x ^= k;
ns[i] = char(x + 65);
}
cout << " your massage after encryption is: " << ns << " (Hex: ";
for (char n: ns) {
if ((n - 65) < 16) cout << 0;
cout << hex << (n - 65);
}
cout << ')' << endl;
}
void XOR() {
int n;
string s;
cout << "welcome to XORCipher, enter the secret letter to start\n";
while (true) {
cin >> s;
if (s.size() == 1) break;
cout << "non-valid letter, please enter one valid letter\n" << endl;
}
while (true) {
cout
<< "what do you want to do? \n 1- do encryption \n 2- do Decryption \n *type any other thing to go to ciphers main menu "
<< endl;
cin >> option;
n = option[0] - 48;
if (n == 1) { XORCipher(toupper(s[0]) - 0); }
else if (n == 2) { XORDecipher(toupper(s[0]) - 0); }
else { return; }
}
}
void rail_fence_enc(const string &s) {
char arr[3][(s.length())];
for (int i = 0; i < 3; i++)
for (int j = 0; j < s.length(); j++)
arr[i][j] = ' ';
bool down = false;
int row = 0, column = 0;
for (char i: s) {
if (row == 0 || row == 2)
down = !down;
arr[row][column++] = i;
if (down) row++;
else row--;
}
string result;
for (int i = 0; i < 3; i++)
for (int j = 0; j < s.length(); j++)
if (arr[i][j] != ' ')
result.push_back(arr[i][j]);
cout << result << endl << endl;
}
void rail_fence_dec(string cipher) {
char arr[3][cipher.length()];
for (int i = 0; i < 3; i++)
for (int j = 0; j < cipher.length(); j++)
arr[i][j] = ' ';
bool down;
int row = 0, column = 0;
for (int i = 0; i < cipher.length(); i++) {
if (row == 0)
down = true;
if (row == 2)
down = false;
arr[row][column++] = '-';
if (down) row++;
else row--;
}
int n = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < cipher.length(); j++)
if (arr[i][j] == '-' && n < cipher.length())
arr[i][j] = cipher[n++];
string result;
row = 0, column = 0;
for (int i = 0; i < cipher.length(); i++) {
if (row == 0)
down = true;
if (row == 2)
down = false;
if (arr[row][column] != '-')
result.push_back(arr[row][column++]);
if (down) row++;
else row--;
}
cout << result << endl << endl;
}
void Rail_fence() {
string message;
int choice;
while (true) {
cout
<< "ahlan ya habibi in Rail fence , what do you like to do \n 1) Cipher \n 2) Decipher \n *press any other key to go back to Ciphers list\n"
<< endl;
cin >> choice;
if (choice == 1) {
cout << "Enter a message to cipher: " << endl;
cin.clear();
cin.sync();
getline(cin, message);
message.erase(remove(message.begin(), message.end(), ' '), message.end());
rail_fence_enc(message);
} else if (choice == 2) {
cout << "Enter a message to decipher: " << endl;
cin.clear();
cin.sync();
getline(cin, message);
rail_fence_dec(message);
} else break;
}
}
int main() {
int q;
while (true) {
cout << "Hello, choose your cipher method:\n"
" 0-Affine\n 1-Caesar\n 2-Atbash\n 3-Vignere\n 4-Baconian\n"
" 5-Simple Substitution\n 6-Polybius Square\n 7-Morse Code\n"
" 8-XOR\n 9-Rail Fence\n\n*Type anything else to exit the program:"
<< endl;
cin >> option;
q = option[0] - 48;
switch (q) {
case 0:
Affine();
break;
case 1:
Caesar();
break;
case 2:
Atbash();
break;
case 3:
Vignere();
break;
case 4:
Baconian();
break;
case 5:
SimpleSubstitution();
break;
case 6:
PolybiusSquare();
break;
case 7:
MorseCode();
break;
case 8:
XOR();
break;
case 9:
Rail_fence();
break;
default:
return 0;
}
}
}