forked from i-am-lax/cpp-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (48 loc) · 1.91 KB
/
Copy pathmain.cpp
File metadata and controls
73 lines (48 loc) · 1.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
#include "playfair.h"
#include <cctype>
#include <iostream>
using namespace std;
int main() {
// Question 1
cout << "====================== Question 1 ======================" << endl;
char prepared[100];
prepare("Come to the Queen's Tower at 7 o'clock!", prepared);
cout << "'Come to the Queen's Tower at 7 o'clock!' has been prepared for ";
cout << "encoding as:" << endl;
cout << "'" << prepared << "'." << endl << endl;
// Question 2
cout << "====================== Question 2 ======================" << endl;
char playfair[6][6];
grid("IMPERIAL", playfair);
cout << "The encoding grid corresponding to the codeword 'IMPERIAL' is:"
<< endl;
for (int row = 0; row < 6; row++) {
for (int col = 0; col < 6; col++)
cout << ((isalnum(playfair[row][col])) ? playfair[row][col] : '?')
<< ' ';
cout << endl;
}
cout << endl;
// Question 3
cout << "====================== Question 3 ======================" << endl;
char out1, out2;
bigram(playfair, 'C', 'O', out1, out2);
cout << "The bigram 'CO' encodes as '" << out1 << out2 << "'" << endl;
bigram(playfair, 'N', '9', out1, out2);
cout << "The bigram 'N9' encodes as '" << out1 << out2 << "'" << endl
<< endl;
// Question 4
cout << "====================== Question 4 ======================" << endl;
char encoded[100];
encode(playfair, prepared, encoded);
cout << "The string '" << prepared << "' encodes as:" << endl;
cout << "'" << encoded << "'" << endl;
// Bonus question
cout << "==================== Bonus Question ====================" << endl;
char decoded[100];
decode(playfair, "VEKVPDQIQDEDEMMVEHSJPVHENOGMIRHVVMEG", decoded);
cout << "The string 'VEKVPDQIQDEDEMMVEHSJPVHENOGMIRHVVMEG' decodes as:"
<< endl;
cout << "'" << decoded << "'" << endl;
return 0;
}