Are there algorithms that enable the creation of a non periodical, theoretically unlimited, sequence of numbers based on an alphanumeric secret key? The idea is to produce always the same unique sequence from a secret alphanumeric key, where the sequence doesn't leak information about the used key, and looks random enough from a cryptographic stance. If the key changes just one bit, the pattern is completely different. Is there a known secure way to produce this?

  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. Also people, please remember not to post answers as comments. This is not a forum, remember? Posting answers as comments creates orphaned questions... which is bound to kill Crypto.SE's purpose. So, just don't do it. Use the answer box instead; that's what it's for. $\endgroup$
    – e-sushi
    Aug 23, 2016 at 17:10

1 Answer 1


There are quite a few options here as you can basically use any algorithm with a single key input and configurable amount of output:

  1. a DRBG (or CSPRNG) such as Hash_DRBG or CTR_DRBG;
  2. a stream cipher or block cipher in streaming mode such as Salsa20 or AES in counter mode;
  3. a KBKDF such as HKDF;
  4. a XOF such as SHAKE256 (SHA-3).

In principle a DRBG - deterministic random bit generator - may seem to be the best option. A DRBG basically turns a seed into a stream of random bytes. It may however request reseeding, which may be a problem. To resolve this, just keep feeding it the same value or zero bytes at the same point in the stream and you should be OK. Furthermore, the DRBG needs to be well defined; some programming API's make changes in the algorithm without notification. This may mean that there are few implementations available - if any, as most of them are simply designed to return unpredictable random numbers. Note that a DRBG is also known as a CSPRNG - a Cryptographically Secure Pseudo Random Number Generator or sometimes just as a PRNG.

A stream cipher takes a symmetric key (and possibly an IV) and turns it into a pseudo random key stream consisting of a virtually unlimited amount bytes. This is completely deterministic and doesn't require reseeding. Note that this key stream was created for encryption rather than randomness. One of the weird properties of counter (CTR or SIC) mode encryption is that it never repeats a block, which distinguishes it from a random stream of bytes. The chance of randomly creating e.g. two identical 128 bit blocks is however infinitely small, so that should not pose a problem.

A KBKDF - Key Based Key Derivation Function - such as HKDF generally can be seen to have an extract and expand phase. First during extraction the entropy in your initial key is put into the state. This state is then used to generate a virtually unlimited amount of bytes. This is called the expansion phase. Problem with this approach is that most of the KDF's expect the output size to be defined in advance.

A XOF - eXtendable-Output Function - can be used by using the key as input for the XOF and defining the random stream as output of the XOF. This is probably the easiest function to use. The input doesn't have to be a particular size and the function was defined to stream out information. The main known XOF's, SHAKE128 and SHAKE256 are however part of the SHA-3 specification and may not be available for all runtimes.

To use your alphanumeric key you first need to convert it into a key that is acceptable to the function that you decide to use. First of all, you'd convert it to binary using character encoding such as ASCII (or UTF-8, which amounts to the same thing).

You may need to use a KDF or hash to generate a key of the right size, in case your DRBG or cipher expects a key of a specific size. In general the leftmost bytes of a hash would also suffice.

In general all of the above are one-way functions so you cannot convert them back to your alphanumeric key apart from brute forcing the alphanumeric key. They all use deterministic (and therefore repeatable) algorithms to generate streams of bytes.

The XOF functions seems to be the main contenders as they are designed for streaming and accepts any size of input data.

AES in counter mode + hash as KDF to create the key - is a very good contender if simply for the reason that it is almost universally available, it's definitely impossible to retrieve the secret key and the output is likely good enough.

  • $\begingroup$ Doesn't the constraint of "non periodical, theoretically unlimited" require infinite state in the PRNG? If so, none of the off the shelf CSPRNG will apply. You could use a variable-length "bignum" as a counter, and then hash that counter (plus whatever other seed state) to generate output. Then increment the counter. This makes the period "infinite" until you run out of memory to store your massive counter. $\endgroup$
    – rmalayter
    Aug 29, 2016 at 13:17
  • $\begingroup$ @rmalayter Yes, that part of the dicussion was moved to chat. Check the comments under the question for more information. The question should have been amended I suppose... Any of the above methods should be able to generate ample output before running into a cycle. $\endgroup$
    – Maarten Bodewes
    Aug 29, 2016 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.