How to generate #Secure random sequence?

How to generate secure random sequence?

Updated title: How to generate secure non repeating random sequence?

I want to generate a sequence of numbers between 1 and 1,000,000 in a random order. Numbers should not repeat itself and not be predictable. E.g. if the first 5 numbers are 134, 5235, 23542352, 25343, 12. It should not be possible to predict the next number. If the upper limit is 2^128, I can use AES/GCM. But what if it is a smaller limit like 1 million?

Lets say, n is 10. I can implement the sequence like below.

numbers = [1, 2,3,4,5,6,7,8,9,10] random_seq = suffle(numbers) # random_seq will be for example. [ 3,7,1,9,8,6,4,5,10,2 ]. 

When if I send first 5 numbers (3,7,1,9,8), no one can predict the 6th number without brute-forcing.

———————————————————————————————————————————–

Lets say, n is 340282366920938463463374607431768211456 (which 2 ^ 128). I can do the below

 key = 8374287 for(i = 1; i < n; ++i) yield AES(i, key) 

No one without key can predict what would be the next number even knowing some or all previous numbers.

-----------------------------------------------------------------------------------------------------------------------------------

My question is what if n is somewhere in-between lets say, 1 million. Is there a better way instead of shuffling numbers between 1 to 1 million? Is there lower size block cipher (though wont be usable as one)? Or is there a different algorithm?

The best I have is,

 sent = set() for(i = 1; i < n; ++i) { next = random_between(1, n) if(sent.contains(next)) continue else: yield next; } 

The problem with this is that I have to remember all sent ones and could be slower or faster for some numbers in sequence.

submitted by /u/EconomyWalrus
[link] [comments]

top scoring links : crypto
Cryptography is the art of creating mathematical assurances for who can do what with data, including but not limited the classical example of encrypting messages so that only the key-holder can read it. Cryptography lives at an intersection of math, programming, and computer science. This subreddit covers the theory and practice of modern and *strong* cryptography, and it is a technical subreddit focused on the algorithms and implementations of cryptography.

Related posts

Leave a Comment