0

[code hidden per academic honesty guidelines]

0

You have a few issues going on here.

If the plain text string is longer than the key, it will go past the end of the key string with unpredictable results. You tried to address this with:

int p = 0;
int k = p % keylen;

but all this does is set k to 0. Doing the % keylen here doesn't do anything later. It needs to be done each time k is incremented. Also, later, there's no need for p. You can simply do something like k = k % keylen.

Your key will be out of synch with the plaintext because you are incrementing k before the encoding instead of after, so you're using the wrong key char - the next one.

This code assumes that the key and the plaintext are both the same case. What about when one is uppercase and the other is lowercase?

That should get you started. There may be other issues.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • I fix this problem but still cipher un correctly it doesnot cipher with key value Apr 6 '16 at 20:13
  • You may have changed something, but if you had actually fixed it, well, it would work. Maybe what you have changed didn't actually fix anything?
    – Cliff B
    Apr 6 '16 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .