C++ (DOS version)
I need tips on creating a C++ program that will encode a message, then when needed decode the same message. It would be base on the following:
RYGCPMJSKAVIZWEBOLQDFTHXUN
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Desktop
I need tips on creating a C++ program that will encode a message, then when needed decode the same message. It would be base on the following:
RYGCPMJSKAVIZWEBOLQDFTHXUN
ABCDEFGHIJKLMNOPQRSTUVWXYZ
by brandonh
Make a class for both functions.
Rough pseudocode (I'm just typing this in, I haven't compiled it).
class Encoder
{
void encode(char* input, char* output, int dataLength)
{
char currentChar;
for (int i = 0; i < dataLength; i++)
{
currentChar = toUpper(input+i);
switch currentChar
{
case 'A':
output+i = 'R';
case 'B':
output=i = 'Y';
...
etc.
Simply reverse the encode function for decoding the message. The input char* and output char* need to point to char arrays of the same length and the output char* needs to be null terminated.
by khinton
by pvp
Ouch! What a pile of coding in Answer 1!
Use two strings: normchar[27]="ABC...Z" and encodchr[27]="RYG...N", then use strchr() to find the source character in normchar[] for encoding or encodchr[] for decoding. Use that index to get the corresponding character from the same position in the opposite string and append it to your output, looping on the input string.
Don't forget the null terminator!
by khinton
by khinton
This discussion is closed to new replies.
Sort by Trending