P
Protoman
Greg said:Protoman said:OK, I'm trying to write a funct to decipher the code, but it keeps
reencrypting it:
string decipher(const string& ciphertext,const string& key)
{
string decrypted;
for(int i=0; i< key.length();i++)
decrypted+=vTable[key-'A'][ciphertext[i%ciphertext.length()]-'A'];
return decrypted;
}
Can you help me? Here's the enciphering funct:
string encipher(const string& cleartext,const string& key)
{
string encrypted;
for(int i=0; i< cleartext.length();i++)
encrypted+=vTable[cleartext-'A'][key[i%key.length()]-'A'];
return encrypted;
}
Any ideas as to what's wrong? It encipher correctly, but it deciphers
wrong. Thanks!!!
To encrypt each character in the message originally, the program used
the clear text letter as an index into the table, and then used the key
as an index along the opposing axis to select the encrypted letter.
To decrypt an encrypted letter, the program performs the same two steps
but in reverse order: it first uses the key to select along the first
axis, and then uses the encrypted letter as an index along the second
axis to locate the plaintext letter.
In other words, if the program encodes a letter with this expression:
vTable[cleartext-'A'][key[i%key.length()]-'A'];
it should then decode it with this one:
vTable[key[i%key.length()]-'A'][encrypted-'A'];
Greg
Thanks!!!!