I am making a C++ console application where the user can encrypt and decrypt text. So far, I have successfully made the encryption part, but am not quite sure how to make the decryption part. For example: abcb -> 128.70.88.70. but I can't make it go back to abcb. Here is my code so far:
Do you understand the limitations of this method of encryption? This is a subsitution cipher, others call it a "Ceasar Shift" cipher and it is very easily broken with frequency analysis.
As coded, you just need to write the reverse function!
Use getch() to get i/p like your encoding function. But add the chars to an array until you reach a '.'. Then you'll need a function to map 128, 70, 88, 80 back to a, b, c, d
You'll also have to renember to handle the last char just after the loop exits.
Andy
P.S. I would split you encode loop out into it's own function before you move on.
Those IF statements are horribly redundant and unnecessary... just cast the char to an int. When you cast a char to an integer, the integer is the ASCII value of the character.
I think your problem might be in the encryption you are trying to use. Do you know what it is called? I believe I was wrong when I said this was a Ceasar Shift, it seems that encr is your actual encrypted message but I can't make heads or tails of it. Where did you read up on this?
You are right, "encr" is the encrypted message and it works just fine. I wrote the code myself and the letters are substituted to a number of my choosing followed by a dot. I'm just trying to get my decryptor working but I have no idea how :(
I can get "abcca" (for example) to go to 128.70.88.88.128.
But I can't get 128.70.88.88.128. to go back to "abcca" :(
unsignedchar cryptTable[255];
for (int a = 0; a < sizeof(cryptTable); a++){
cryptTable[a] = a;
}
//now set up your swaps
cryptTable['a'] = 'b'; //needs the single quotes
cryptTable['b'] = 'a';
//etc.
(I would put all of this in a class, if I were you, if you know how)
this way you can simply write a function to swap characters directly.
This in conjunction with xor encryption and some simple algorithms (including salting the data) would make a somewhat difficult to break encryption.