General discussion

Locked

C++ (DOS version)

By khinton ·
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

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

C++ (DOS version)

by brandonh In reply to C++ (DOS version)

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.

Collapse -

C++ (DOS version)

by khinton In reply to C++ (DOS version)

The question was auto-closed by TechRepublic

Collapse -

C++ (DOS version)

by pVp In reply to C++ (DOS version)

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!

Collapse -

C++ (DOS version)

by khinton In reply to C++ (DOS version)

The question was auto-closed by TechRepublic

Collapse -

C++ (DOS version)

by khinton In reply to C++ (DOS version)

This question was auto closed due to inactivity

Back to Desktop Forum
5 total posts (Page 1 of 1)  

Related Discussions

Hardware Forums