![]() |
modulo arithmetic question
I am writing a program that deals with ciphers and codes. When the user enters a set of text and a number after being prompted, they are taken to this function:
:
for (i = 0; i < len; i++)I want the resulting workingtext to only be a letter a-z, not any of the wierd computer characters (e.g. smiley faces, musical notes and french circumflex accents (just some of my favourites)). I think that it probably just requires a modulo thingy in here somewhere, can some one indicate where? |
ASCII normal printing characters are only d32 to d126. A-Z is d65-d90, and a-z is d97-d122. http://www.lookuptables.com/
|
assuming that the characters entered by the user lie between a-z, you can do
:
workingtext[i] = 97+(workingtext[i] + ikey)%26; |
You could also construct an array for your desired character set that would be filled in at runtime in a way sensitive to the locale, then apply your modulus function according to the length of the array. If you're a portability kind of person. I'm (perhaps unfortunately) not.
|
Thanks guys, haven't tried it yet, but from what i can see it should do what i want so thanks...
|
This is ROT encryption.
More info: http://en.wikipedia.org/wiki/ROT13 |
Ah! I tried it but it didn't work! If you try and use 1 as the key, it outputs with a key of 20!
Anyone know why? |
| All times are GMT -5. The time now is 5:35 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC