mercredi 13 juillet 2016

Large Random Number String with Maximum Numeric Value for Substrings

More of a number question than programming, but here goes: Say I want to implement a basic form of cryptography, where every character in a document is assigned a random number corresponding to a "shift" in character positions.

For example, I have a string "hello" and the "random" numbers 02, 05, 03, 09, and 01. If the char 'h' is shifted by 2 characters (and the character set contains only the lowercase Latin alphabet a-z), and so on for each character and sequential number, the string becomes "jkpvi".

Now assume instead of generating random numbers per character, I want to generate one large random number which is then split into smaller, two character numbers. So numbers 02, 05, 03, 09, and 01 would represented instead by 0205030901.

The problem with this is that the maximum value of one of these smaller two characters could be 99, much greater than 26 (or 27 if using a space character).

So, given a large random number foo, how can I break it into smaller two digit numbers bars so that each number is within the range 0-26, or rather set the maximum value of each number to be less than 99?

Just to be clear, I understand random number generation, pseudo-random numbers, and things like /dev/random vs. /dev/urandom. I'm only interested in generating several two digit values with a maximum of less than 99 given a large, predetermined pseudo-random number.

Also, ignore the string terminology in the question title, it was simply easier to refer the the lengthy random number as a string to be modified as opposed to something like a BigInt() or what have you.




Aucun commentaire:

Enregistrer un commentaire