Hey all im working on a program that has gives you the option of converting a message(string) into 3 different schemes: Prime Shift Encoding scheme, Shifty Encoding Scheme, and a Reverse Encoding scheme. I have figured out how to encode and decode the prime shift scheme and reverse scheme, but im having a little bit of trouble with the Shifty Encoding scheme. The rules for the Shifty scheme are these: Each character in the message is converted to its ASCII value. The value is subtracted from 1000, resulting in a triplet of numbers. Each digit of the triplet is then converted to the symbolic value on the keyboard above the numbers 1 – 0. The string of symbols is the encoded message.

For example, if the character’s value is 37, it is subtracted from 1000, resulting in a triplet of 963. The corresponding keyboard characters are (^#.

The encoded message is then stored in a text file along with the key, and the number that corresponds to the scheme. When the user clicks on the decode button a filechooser opens up and the user selects the text file to read in. Once he/she selects the file they want open the program reads in the encoded message the key and the scheme. So the program must be able to get the encoded message and convert it back to its original message.

I have figured out the code to encode the Shifty scheme and it encodes the message perfectly, but im lost on how to decode the message. I know i have to somehow obtain each of the triplet of digits back from the encoded string and then subtract 1000 from each one so i can get the correct ascii character, but im lost on how to do that. Any help would be appreciated.

so far i have this:

    keyBoard[0] = ')';
    keyBoard[1] = '!';
    keyBoard[2] = '@';
    keyBoard[3] = '#';
    keyBoard[4] = '$';
    keyBoard[5] = '%';
    keyBoard[6] = '^';
    keyBoard[7] = '&';
    keyBoard[8] = '*';
    keyBoard[9] = '(';

void ShiftyEnigma::encode()
    stringstream ss;
    stringstream s1;
    int value = 0;
    for(unsigned int i = 0; i < codedMessage.length(); ++i)
        int ascii = codedMessage.at(i);
        //subtracting 1000 from ascii number of each character in message
        value = 1000 - ascii;
        //setting the value in string stream in order to convert each digit of 
        //triplet (ex 887) into values that match the keyboard array
        ss << value;
        for(unsigned int i = 0; i < ss.str().length(); ++i)
            s1 << keyBoard[(int)ss.str().at(i)-48];
    codedMessage = s1.str();
void ShiftyEnigma::decode()
    for(unsigned int i = 0; i < codedMessage.length(); ++i)
3 Years
Discussion Span
Last Post by plenty.groover

I think you answered the question with your question, simply read in three characters each time and proceed from there... :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.