0

I am creating a program to decrypt the line of code ":mmZ\dxZmx]Zpgy" with ASCII method. What I have so far translates individual characters perfectly. But I can't seem to translate whole lines/words. Everyway I've tried gives an error somewheres. I think I need to use cstring or string. Any tips or pointers would be greatly appreciated.

#include <iostream>
using namespace std;

char Decryption(char OriginalChar, int Key); // Function declaration: Decrypts a secret code

int main()
{
    char OriginalChar, Secret_Code;
    int Key;

    cout << "Please enter the Original Character: \n";
    cin >> OriginalChar;
    cout << "You entered " << (int) OriginalChar << endl;

    Secret_Code = Decryption(OriginalChar, Key); // Function Call: Computes secret code

    system("pause");
    return 0;
}

char Decryption(char OriginalChar, int Key) // Function Definition: Outputs secret code
{
    char Secret_Code;


    for (Key = 0; Key <= 100; Key++)
    {

    if (OriginalChar - Key < 32) 
    {
         Secret_Code = (((OriginalChar - Key) + 127) - 32); //Decrypts the code
    }
    else 
    {
        Secret_Code = (OriginalChar - Key); //Decrypts the code
    }
        cout << endl << "Key: " << Key << endl << "This translates to: " << (char) Secret_Code << endl;
    }

    system("pause");
    return (Secret_Code);
}
2
Contributors
1
Reply
4
Views
4 Years
Discussion Span
Last Post by Moschops
0

What I have so far translates individual characters perfectly. But I can't seem to translate whole lines/words.

You read the input into the variable originalChar, which is a char. One char. Your function for decoding takes in one char, and the key, and returns one char. If you want to enter more than one char, you'll have to put it into a variable than can hold more than one char. I suggest a string.

This topic has been dead for over six months. 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.