Advertisement
edo_py

hex2txt (debug text variable)

Dec 21st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. // usage: hex2txt [hex_code]
  6. string input, func, args;     // global strings
  7.  
  8. string hex2txt(string hex){
  9.    
  10.     hex.erase(0, 8);
  11.    
  12.     if (hex.length() != 0){
  13.        
  14.         unsigned int evenOrOdd = hex.size() % 2;
  15.    
  16.         if (evenOrOdd == 0){
  17.            
  18.             string text;
  19.    
  20.             for (int i = 0; i < hex.size(); i++){    // erase all spaces from input
  21.                 if (hex[i] == ' ')
  22.                     hex.erase(i, 1);
  23.             }
  24.             cout << hex << endl; //debug
  25.            
  26.             string hex_part;
  27.    
  28.             char* hexTable [256] =
  29.             {
  30.                 "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31",
  31.                 "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43",
  32.                 "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55",
  33.                 "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67",
  34.                 "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  35.                 "7a", "7b", "7c", "7d", "7e", "7f"
  36.             };
  37.    
  38.             char* alphanumTable [256] =
  39.             {
  40.                 " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5",
  41.                 "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
  42.                 "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a",
  43.                 "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
  44.                 "x", "y", "z", "{", "|", "}", "~"
  45.             };
  46.    
  47.             for (int i = 0; i < hex.size(); i+=2){    // translate hex to text
  48.        
  49.                 hex_part.push_back(hex[i]);
  50.                 hex_part.push_back(hex[i+1]);
  51.        
  52.                 for (int e = 0; e < hex.size(); e++){
  53.                     if (hex_part == hexTable[e])
  54.                         strcpy(alphanumTable[e], text.c_str());
  55.                     else
  56.                         continue;
  57.                 }
  58.                 cout << "text: " << text << endl; //debug
  59.        
  60.                 hex_part.erase(0, 2);
  61.    
  62.             }
  63.             cout << "text: " << text << endl; //debug
  64.             return text;
  65.         }
  66.         else
  67.             return "ERROR: Invalid HEX code.";
  68.     }
  69.     else
  70.         return "ERROR: Missing HEX code.";
  71. }
  72.  
  73. int main(){
  74. //  if (func == "hex2txt"){
  75.     cout << hex2txt("hex2txt 2b3c4f") << endl;   // example
  76. //  cout << hex2txt(input);
  77. //  }
  78.     system("PAUSE");
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement