53 std::transform(text.begin(), text.end(), text.begin(),
55 std::replace(text.begin(), text.end(),
':',
' ');
56 for (
char letter : text) {
58 result += std::to_string(
59 a1z26_encrypt_map[letter]);
78std::string
decrypt(
const std::string& text,
bool bReturnUppercase =
false) {
82 std::vector<std::string> word_array;
83 std::stringstream sstream(text);
85 while (sstream >> word) {
86 word_array.push_back(word);
89 for (
auto& i : word_array) {
90 std::replace(i.begin(), i.end(),
'-',
' ');
91 std::vector<std::string> text_array;
93 std::stringstream ss(i);
95 while (ss >> res_text) {
96 text_array.push_back(res_text);
99 for (
auto& i : text_array) {
100 result += a1z26_decrypt_map[stoi(i)];
107 if (bReturnUppercase) {
108 std::transform(result.begin(), result.end(), result.begin(), ::toupper);
122 std::string input =
"Hello World";
123 std::string expected =
"8-5-12-12-15 23-15-18-12-4";
124 std::string output = ciphers::a1z26::encrypt(input);
126 std::cout <<
"Input: " << input << std::endl;
127 std::cout <<
"Expected: " << expected << std::endl;
128 std::cout <<
"Output: " << output << std::endl;
129 assert(output == expected);
130 std::cout <<
"TEST PASSED";
133 input =
"12-15-23-5-18-3-1-19-5";
134 expected =
"lowercase";
135 output = ciphers::a1z26::decrypt(input);
137 std::cout <<
"Input: " << input << std::endl;
138 std::cout <<
"Expected: " << expected << std::endl;
139 std::cout <<
"Output: " << output << std::endl;
140 assert(output == expected);
141 std::cout <<
"TEST PASSED";
144 input =
"21-16-16-5-18-3-1-19-5";
145 expected =
"UPPERCASE";
146 output = ciphers::a1z26::decrypt(input,
true);
148 std::cout <<
"Input: " << input << std::endl;
149 std::cout <<
"Expected: " << expected << std::endl;
150 std::cout <<
"Output: " << output << std::endl;
151 assert(output == expected);
152 std::cout <<
"TEST PASSED";