i am having problem in making the final enciphering equation. actually i am confused with this ASCII part. not asking for code . just a helpful understanding of this ASCII part.


can you be more specific? ASCII is just the numeric code corresponding to each letter of the alphabet, so "A" for example has the ASCII code of 65, so if key is 2, which means shift each letter by 2, A becomes C, ASCII code of C is 67, which is just 65 + 2.

  • This does not make wrapping easy which is the most difficult part of the problem IMHO.
    – Nick Young
    Jan 22 '16 at 17:34

You can greatly simplify the problem by remembering that a "char" is just an 8-bit int. This means math works as expected.

'A' - 'A' = 0; 
'B' - 'A' = 1;

This means you don't even have to worry about what each letter is you can simply subtract either 'A' if its upprcase (isupper(char)) or 'a' if its not (!isupper(char)) that will give you the distance from 'a' or 'A' and you can perform math on that. Add your shift value, modulo (% operator) it and then add 'A' or 'a' back to the value.

1 + 'A' = 'B';
2 + 'a' = 'c';

when you remember this fact working with any kind of chars becomes much easier.


You must log in to answer this question.

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