Creating and using a lookup array

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!!!!
 
P

Protoman

How do I turn this into an cleartext autokey; it only needs one letter
to start the show.
 
K

Karl Heinz Buchegger

Protoman said:
How do I turn this into an cleartext autokey; it only needs one letter
to start the show.

How do you turn *what* into an cleartext autokey?

Protoman. You have been advised so many times to include some context
into your postings. You should already know the rules of this group.

* Quote from the message you are replying to, in order to create a context
of your posting (everybody knows what you are talking about, just by looking
at this single post).

* Post the code you already have and ask specific questions about it.
This not only raises your chance that somebody might answer. It also
allows us to figure out what you already know and tailor our answers
to your level of knowledge (There is always more then one way to skin
a cat).

* If you have error messages from the compiler, post them also. Mark the line
the error message talks about, such that nobody has to count lines in a newsreader.

* Always keep in mind: You have probably spent hours on your problem and couldn't solve
it. We see your problem just for 5 seconds and most often we don't see all of your code.
So if you could not figure it out for hours how do you expect anyone to sort it out
in a few seconds?
So post everything related to your problem. If in doubt post the entire program

* Shorten your program and remove everything not related to your actual problem.
If eg. you have troubles in writing a file, then most likely the code to list
data on cout is not related to it. Remove that code -> shorter program

Before you post that: make sure, your problem is still in the sortened program.

Yes: This requires some work from you. But in a lot of cases during this 'code stripping'
the problem is discovered by the OP. And there is nothing better then a problem that you
can solve on your own.

If you still fear that work, then remember that *we* have to do that work. And we are
lazy. So if in doubt, we refuse to do that work. Work that could have been done by the OP.
-> You don't get an answer.

* Be nice to us and we are nice to you.
 
P

Protoman

I do not fear work!!!!!!!!!!!! I pratically did the whole thing myself,
and I found an easier method of doing it!!! To do an autokey, you need
to take a "priming key", like X, and append the cleartext to it, until
the key length equeals the cleartext length.
 
H

Howard

Protoman said:
I do not fear work!!!!!!!!!!!! I pratically did the whole thing myself,
and I found an easier method of doing it!!! To do an autokey, you need
to take a "priming key", like X, and append the cleartext to it, until
the key length equeals the cleartext length.

Congratulations. Not that we have any idea what the heck you are talking
about, of course. Which part of the earlier conversation (re-posted below)
did you not understand?
Protoman. You have been advised so many times to include some context
into your postings. You should already know the rules of this group.

* Quote from the message you are replying to, in order to create a context
of your posting (everybody knows what you are talking about, just by
looking
at this single post).

(Do you need instructions on how to quote from the message to which you're
replying?)

-Howard
 
G

Greg

Protoman said:
Yes, how do I quote?

Since it appears that you are using Google as your news reader, I will
give you Google specific instructions. Quoting is actually very easy,
much easier than implementing a Vigenere encrypter, that is for sure.

The trick is when replying to a posting do NOT click on the "Reply"
link under the news posting. Instead click on the "Show Options" link
on the top line of the posting next to the date. Doing so reveals a
line of additional options including a "Reply" link. DO click on this
reply link since it will include the message text from the original
posting in your reply. Edit to suit.

Hope that helps,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top