Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // usage: hex2txt [hex_code]
- string func, args; // global strings
- string hex2txt(string hex){
- hex.erase(0, 8);
- if (hex.length() != 0){
- unsigned int evenOrOdd = hex.size() % 2;
- if (evenOrOdd == 0){
- string text;
- for (int i = 0; i < hex.size(); i++){ // erase all spaces from input
- if (hex[i] == ' ')
- hex.erase(i, 1);
- }
- string hex_part;
- char* hexTable [256] =
- {
- "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31",
- "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43",
- "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55",
- "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67",
- "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
- "7a", "7b", "7c", "7d", "7e", "7f"
- };
- char* alphanumTable [256] =
- {
- " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5",
- "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "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", "[", "\\", "]", "^", "_", "`", "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", "{", "|", "}", "~"
- };
- for (int i = 0; i < hex.size(); i+=2){ // translate hex to text
- hex_part.push_back(hex[i]);
- hex_part.push_back(hex[i+1]);
- for (int e = 0; e < hex.size(); e++){
- if (hex_part == hexTable[e])
- strcpy(hexTable[e], text.c_str());
- else
- continue;
- }
- hex_part.erase(0, 2);
- return text;
- }
- }
- else
- return "ERROR: Invalid HEX code.";
- }
- else
- return "ERROR: Missing HEX code.";
- }
- int main(){
- // if (func == "hex2txt"){
- cout << hex2txt("hex2txt 2b3c4f") << endl; // example
- // }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement