Hi, I am writing an encryption program and I want there to be only numbers and letters in the encryption. My offset is going to be a random number between 8 and 15, so I need to figure out how to wrap numbers on the interval [0,9]. I have been playing around with this for a while now and can't seem to get it to work, although it seems like it should be fairly straight forward. Any help is much appreciated.
But i do know what you want, it seems that you are messing numbers with characters. As in ASCII all numbers are characters, 1 is a number, but '1' is a character, "1" is a string. And luckily numbers and letters are consective in ASCII, so you don't have to do anything special with 0-9, just deal with them like you do with letters, add offset, and mod it to keep it in range.
@yueeng Thanks, I figured out how to solve my problem. I was subtracting 10 because I want the encryption to consist of only lowercase characters a-z, 0-9. Say the character you want to have encrypted is '9' and the offset is 15. I need it to count through the sequence of characters 0,1,2,3,4,5,6,7,8,9, and once it gets to 9 continue counting at 0. So for '9' with an offset of 15, count through that sequence 15 spaces and you get 4. That is why I needed to wrap the numbers. I was on the right track, just was not going about it in quite the right way. Here is what I ended up getting to work for a random offset value between 8-15:
note:
message[i] is the number corresponding to the ascii character between 0-9
offset is a random value between 8-15