0

I wanted to know to encipher the plaintext given by the user depending on the keyword provided by the user. And then according to the index number of the alphabets of the keyword will the program shift the letters in the message by that many alphabets. Here is my code below :

P.S : If any other bugs with my program please let me know.

Thank you, Shayan

enter image description here

1
  • Just a suggestion, you can copy paste the relevant code into your question rather than an image. Just encase the image dies in future and is unable to help future students,
    – user7869
    Aug 4, 2015 at 22:55

1 Answer 1

0

Everything looks pretty good, except the fact that you are doing what you want to do.

On the final part of your code, where you populate the shift array, you are assigning to its members the distance of each character from the beginning of A or a, by subtracting the integer value of A or a respectively. So if the plaintext is AbCd your shift array would be [0, 1, 2, 3], which is not what you want.

What you need to do is move each letter, a number of places to the right, which number is given to you by the key. So if your plaintext is AbZ and your key is abc, the encrypted text should be AcB because a has index 0, b has index 1 and c has index 2. So A becomes A + 0 == A, b becomes b + 1 == c and Z becomes Z + 2 == B. Hope that gets you going.

Edit after comment

Since you have already created the shift array correctly, create another string with the name encrypted_text for example, with length the same as the length of plaintext. Then assign at each index the same letter of plaintext moved by shift[i]. Be sure to check if the move of the letter gets past the end of the alphabet. I can't help you more without breaking the rules of the Academic Honesty. Re-watch the walkthroughs if needed.

3
  • yeah but the thing is I don't know how to do it, can you give me one more hint on how to solve the problem. Aug 5, 2015 at 11:33
  • sure thank you so much that is all I need to finish the program. Aug 5, 2015 at 20:21
  • You can mark the answer as accepted then :) Happy coding
    – ChrisG
    Aug 5, 2015 at 20:22

You must log in to answer this question.

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