-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvigenere.cpp
54 lines (35 loc) · 950 Bytes
/
vigenere.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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string createLine(char);
vector<string> createTable(char);
char get_crypt_key(char, char)
int main(){
vector<string> table = createTable('A');
for (auto elem: table) {cout << elem << endl;} //C++11
return 0;
}
string createLine(char start){
string res;
if (start >= 'a' && start <= 'z')
start -= 32;
for (int i=0; i<26; i++){
char c = start + i;
if (c < 'Z') res += c;
else res += (c-'A')%26 + 'A';
}
return res;
}
vector<string> createTable(char start='A'){
vector<string> v;
for (int i=0; i<26; i++)
v.push_back(createLine(start+i));
return v;
}
char get_crypt_key(char letter_message, char letter_key){
string column = createLine('A');
string line = createLine(letter_key);
size_t pos = column.find_first_of(letter_message, 0);
return line.at(pos);
}