216std::string decrypt(
const std::string &text) {
219 std::string decrypted_text =
"";
222 std::size_t pos_start = 0, pos_end = 0, delim_len = 1;
223 std::vector<std::string> splits;
224 while ((pos_end = text.find(
' ', pos_start)) != std::string::npos) {
225 std::string token = text.substr(pos_start, pos_end - pos_start);
226 pos_start = pos_end + delim_len;
227 splits.push_back(token);
231 for (
const std::string &s : splits) {
236 return decrypted_text;
247 std::string text1 =
"01234567890";
248 std::string encrypted1 = ciphers::morse::encrypt(text1);
249 std::string decrypted1 = ciphers::morse::decrypt(encrypted1);
250 assert(text1 == decrypted1);
251 std::cout <<
"Original text : " << text1 << std::endl;
252 std::cout <<
"Encrypted text : " << encrypted1 << std::endl;
253 std::cout <<
"Decrypted text : " << decrypted1 << std::endl;
255 std::string text2 =
"abcdefghijklmnopqrstuvwxyz";
256 std::string encrypted2 = ciphers::morse::encrypt(text2);
257 std::string decrypted2 = ciphers::morse::decrypt(encrypted2);
258 assert(text2 == decrypted2);
259 std::cout <<
"Original text : " << text2 << std::endl;
260 std::cout <<
"Encrypted text : " << encrypted2 << std::endl;
261 std::cout <<
"Decrypted text : " << decrypted2 << std::endl;