Uniform distribution on 255 from text [closed]

I'm trying to create a way to link letters from a text to a position between 1 to 255.

For example, the text is : "stackexchange" I would like to link every letter to a number between 1 and 255. The same word should have the same output and the overall should be uniform (if I give lots of input, I would like to have an uniform distribution.) // And of course, I want that "stackexchange" always give the same output.

// e.g. s=>12 || t=>88 || a=>65 || c=>214 || ... || c=>142 ||...

Could you help me ? Thanks !

closed as not a real question by russellpierce, gung - Reinstate Monica♦, Peter Flom - Reinstate Monica♦, Andy W, cardinalMar 7 '13 at 2:20

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

• What does overall should be uniform mean? If $c$ is so much less common thn $a$ how can the distribution be uniform? i.e. $65$ will occur much more often than $214$. – curious_cat Mar 4 '13 at 14:25
• Well, because the letter c shouldn't always give 214. (c=>142 for the 2nd time) – fast_cen Mar 4 '13 at 14:48
• @MrBenderV You said "the same letter should have the same number". And in the comment "the letter c shouldn't always give 214". Can you clarify? – ziggystar Mar 4 '13 at 15:16
• @ziggystar Clarified, I meant the same word to have the same input (an array of length(word) of number between 1 and 255). – fast_cen Mar 4 '13 at 15:19
• Why not just use a random number generator then, and use the word as the seed for the generator, outputting N numbers for a word of length N? – Corone Mar 4 '13 at 15:32

Corone's comment is by far a simpler method as what I am proposing.

First, you don't want a function from letters to numbers, since then you would only produce about 50 values.

In general a function, which maps pairs of words and positions in those words to [1,255] seems what you want to have.

Possible Solution

One possibility would be mapping the sequence of the k last letters in the word to numbers.

Example for k=3

input: stackexchange
inputs:      s
(s)  t
(st) a
(ta) c
(ac) k
...


Then you have to find a mapping for all possible at most k-length sequences, which maximizes uniformity. This is probably done by training on some sample text body.

• +1; The sample body is going to be critical. For example, words like "a", "of", "the" etc may appear a bunch in a corpus and completely bork any attempt to make the distribution uniform. – russellpierce Mar 4 '13 at 18:21

Thanks to yours ideas, I think I have found something that can help.

I will sha-1 my word.

e.g. stackexchange will give "19f054f1f448ff152f1d586be39a56f179fe80c9"

Each letter had [10 (0 to 9) + (a-f) 6] => 16 output possible.
If I take two letter each time. I give me (16*16) 256 output different.

If the output is 256 (less than 0.5% chance), I don't take into account and move to the two next letter, and try again.

e.g. with stackexchange :

'19' = (1,9) => link to (16+10=26) 26

'f0' = (15,0) => link to (15*16+1=241) 241 ...

After I can easely solve the problem of output size, ect.

Again ;Thank you @ziggystar and @Corone for the help and the ideas !

• Well a SHA hash like the one you are describing takes on values between 0 and 255, so you don't have to worry about it turning out as 256, but you might have to worry about it coming out at 0 (although I can't imagine why). The other issue is that there are no guarantees that the distribution of values in a SHA hash are uniform (a quick adhoc look suggests that they might not be). – russellpierce Mar 5 '13 at 4:21
• SHA should pass uniformity for single use, otherwise this would lead to cryptographic weakness. However, the vector properties may not be uniform, e.g. if you take N words and SHA them together, that might not be uniform in N dimensional space. – Corone Mar 5 '13 at 9:43