![]() |
| | #1 |
| Registered User Join Date: Apr 2007
Posts: 42
| Methods to keep a number within a certain range? 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? |
| osiris^ is offline | |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,131
| Show example please.
__________________ Mac and Windows cross platform programmer. Ruby lover. |
| Dino is offline | |
| | #3 |
| Registered User Join Date: Apr 2007
Posts: 42
| 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];
}
Code: for (m = 0; m < strlen(key_ext); m++)
{
keynums[m] = (int)key_ext[m];
}
I'm not really sure how to do this, and would like to know if anyone can throw in some ideas. |
| osiris^ is offline | |
| | #4 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,131
| Is this a class assignment, such that you cannot use the obvious solution?
__________________ Mac and Windows cross platform programmer. Ruby lover. |
| Dino is offline | |
| | #5 |
| Registered User Join Date: Apr 2007
Posts: 42
| 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. |
| osiris^ is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| checking the number (int/double) range | l2u | C++ Programming | 7 | 08-05-2008 05:27 AM |
| Random number + guessing game trouble | Ravens'sWrath | C Programming | 16 | 05-08-2007 03:33 AM |
| Stone Age Rumble | KONI | Contests Board | 30 | 04-02-2007 09:53 PM |
| Prime number program problem | Guti14 | C Programming | 11 | 08-06-2004 04:25 AM |
| Random Number problem in number guessing game... | -leech- | Windows Programming | 8 | 01-15-2002 05:00 PM |