-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigital_cypher_2.cpp
39 lines (35 loc) · 944 Bytes
/
digital_cypher_2.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
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
class Kata
{
public:
static std::string Decode(std::vector<int> code, int n)
{
std::vector<int> key_vector;
while(n > 10){
int reminder = n%10;
key_vector.push_back(reminder);
n /= 10;
}
key_vector.push_back(n);
std::reverse(key_vector.begin(), key_vector.end());
std::stringstream codestring;
int key_length = key_vector.size();
for(size_t i = 0; i < code.size(); ++i){
int codeValue = code.at(i);
int deleteValue = key_vector.at(i % key_length);
int alphabetValue = codeValue - deleteValue + 96;
std::cout << (char)alphabetValue << std::endl;
codestring << (char)alphabetValue;
}
return codestring.str();
}
};
int main(){
std::vector<int> codeVector {20, 12, 18, 30, 21};
int key = 1939;
std::cout << Kata::Decode(codeVector, key) << std::endl;
return 0;
}