# Thread: Methods to keep a number within a certain range?

1. ## Methods to keep a number within a certain range?

Hi all,

I have numbers X and Y, which have to be used to perform a calculation such that the resulting number, Z, is always within a particular range. However, as I'll need to find the inverse of this calculation to return to X or Y, I cannot use the modulus operator.

Anyone got any ideas?

3. Well, I didn't need any code to do it, I just wanted ideas on how to do it.

However, here's the code which gets the unicode numbers from a string called 'plain'. Each character of the array refers to a number iin nums[], which corresponds to A from my original post.

Code:
```for (m = 0; m < strlen(plain); m++)
{
nums[m] = (int)plain[m];
}```
Here is the code which gets the unicode numbers from a string called 'key_ext'. Each character of which refers to a number in keynums[], which is B in my original post.

Code:
```for (m = 0; m < strlen(key_ext); m++)
{
keynums[m] = (int)key_ext[m];
}```
For example, if nums[0] was 56 and keynums[0] was 109, I need to do something specific to these two numbers to consistently produce a result between 32 and 127. The method by which this is done would also need to be reverseable.

I'm not really sure how to do this, and would like to know if anyone can throw in some ideas.

4. Is this a class assignment, such that you cannot use the obvious solution?

5. Originally Posted by Dino
Is this a class assignment, such that you cannot use the obvious solution?
It's part of an encryption program assignment, which is why I cannot use the mod operator, as the inverses aren't always precise, so I may end up with multiple solutions when I try to decrypt. This specific section is using the Vernam Cipher, but it's only one part of my encryption/decryption algorithm. My full algorithm involves the above mentioned vernam cipher, shift substitutions and columnar transpositions over multiple iterations.