Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * helloworld.cpp
- */
- #include <iostream>
- #include <string>
- #include <functional>
- #include <algorithm>
- #include <unordered_map>
- class SecretMessage : private std::string
- {
- private: typedef std::unordered_map<std::string, char> hashtable;
- private: typedef std::function<void(char)> callback;
- public: class Cypher : hashtable
- {
- friend class SecretMessage;
- private: uint8_t __chunk_size;
- public: Cypher(std::string const &key)
- : hashtable()
- {
- parse(key);
- }
- public: Cypher &parse(std::string const &key)
- {
- size_t key_offset = key.find(' ');
- uint8_t size = (uint8_t) std::stoi(key.substr(0, key_offset));
- uint8_t ichar = 0;
- __chunk_size = size;
- for (size_t i = key_offset + 1; i < key.size(); i += size)
- {
- std::string const &key_chunk = key.substr(i, size);
- insert({key_chunk, (char) ichar});
- ++ichar;
- }
- return *this;
- }
- };
- public: class Printer : private std::string
- {
- public: Printer()
- : std::string()
- {
- }
- public: Printer &print(char c)
- {
- if (size() == 0 || back() == ' ')
- c = toupper(c);
- else
- c = tolower(c);
- push_back(c);
- std::cout << c;
- return *this;
- }
- };
- private: std::string __decrypted;
- public: SecretMessage(std::string const &msg)
- : std::string()
- {
- for (auto const &c : msg)
- if (c != ' ')
- push_back(c);
- }
- public: SecretMessage &unlock(Cypher const &cypher)
- {
- __decrypted.clear();
- for (size_t i = 0; i < size(); i += cypher.__chunk_size)
- {
- std::string const &chunk = substr(i, cypher.__chunk_size);
- char c = cypher.at(chunk);
- __decrypted.push_back(c);
- }
- return *this;
- }
- public: SecretMessage &traverse_characters(callback on_traverse)
- {
- for (auto const &c : __decrypted)
- on_traverse(c);
- return *this;
- }
- };
- int main()
- {
- SecretMessage::Printer printer;
- SecretMessage(
- "74OR!xE-tl6BF@~B"
- "vD%dH!+vvD%dH!+v"
- "3/c\\;c2t^-;n\\,"
- "Z,jP4km65Qae+WF!"
- "J/3/c\\;c2twbMAy"
- "(3.vD%dH!+vTLH&V"
- "Bf7XzvMJWC! "
- )
- .unlock(
- SecretMess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_Aep%S^[+*2"
- "bn*7iSij/V7t$fZK@2eHTgBdCq~b*MI%"
- "'AL3LH_wFkn21idL901Ox.Vimr8'wRYX"
- "#zvNkUgWX-NnM\\[5$_mGgEw_=sKX3JH"
- "A_*G[Y&E7V4lu_"
- )
- )
- .traverse_characters(
- [&](char c){printer.print(c);}
- );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement