Advertisement
asqapro

Serialization

Jul 24th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. struct bin{
  2.     vector<int> modify_string;
  3.     map<string, int> encryption;
  4.     void set_up_code(){
  5.         string alphabet[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  6.         int letter_num=1;
  7.         for(int i = 0; i < 27; ++i){
  8.             string letter = alphabet[i];
  9.             encryption.insert(pair<string,int>(letter,letter_num));
  10.             letter_num++;
  11.         }
  12.     }
  13.     void encrypt(string& crypt){
  14.         for(unsigned int i = 0; i < crypt.size(); ++i){
  15.             stringstream ssl;
  16.             string letter;
  17.             char let = crypt[i];
  18.             ssl << let;
  19.             ssl >> letter;
  20.             int num = encryption[letter];
  21.             modify_string.push_back(num);
  22.         }
  23.     }
  24.     void decrypt(vector<int>& uncrypt){
  25.         map<string, int>::iterator it;
  26.         for(unsigned int i = 0; i < uncrypt.size(); ++i){
  27.             int number = uncrypt[i];
  28.             for(it = encryption.begin(); it != encryption.end(); ++it){
  29.                 if(it->second == number){
  30.                     cout << it->first;
  31.                     break;
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }binary;
  37.  
  38. binary.set_up_code();
  39. character.race_class = "human_orc";
  40. binary.encrypt(character.race_class);
  41. binary.decrypt(binary.modify_string);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement