look at http://www.asciitable.com/ as you can see here ever single character has a numeric value attached to it. Now what you do it you take one character and you convert it to it's ascii value:
Code:
char x = '\0';
int ascii = 0;
cin.get(x);
ascii = (int)x;
so now ascii holds the numerical value for the character x. Second you need a 2d array that has first the ascii value of the first/original character as it's index and then the ascii value of the encoded character:
Code:
int Table[256] = { 35,
67,
........
79 };
Please note that the encoded and original values were picked at random by me =].
Now following the above code given when you do something alike:
Code:
char encoded = (char)Table[ascii];
To decypher your code you can either build a new array that would have 1 stored in it's 35th element (following the above example) or you could have a for loop that goes through the original array and finds the encoded value and then uses the index as the decyphered value:
Code:
int Decode[256] = { ......
1, // 35th element
......
2, // 67th element
......
256, // 79th element
...... };
char original = (char)Decode[ (int)encoded ];
-or-
Code:
for(int i = 0; Table[i] != (int)encoded; i++)
{}
char original = (char)i;
note that the first example with a new array takes more memory and that the second example with the for loop takes more CPU time. So it is up to you to decide which you value more...