[Cryptography] An interesting little pseudorandom number generator

Ray Dillinger bear at sonic.net
Sun Aug 1 13:23:48 EDT 2021


Ergh.  Noticed a typo in most recent posted version.  Idx1 was getting
set to the wrong thing, creating a short-range correlation by making it
possible for the same two elements to be combined to make two different
outputs. 

Apologies to anyone who cut/pasted, compiled, and watched Diehard
immediately barf on it.

            Bear


Corrected, again:

uint64_t A[256];uint32_t N;
uint64_t pseudorandom(){
    N--;
    A[N%256] = A[(N+5)%256] + A[(N+17)%256];
    A[(N+17)%256] = A[(N+41)%256] ^ A[(N+72)%256];
    A[(N+72)%256] = A[(N+120)%256] * A[(N+161)%256];
    A[(N+161)%256] = A[(N+163)%256] + A[(N+254)%256];
    int idx1 = N%256; int idx2=(A[(N+17)%256]+A[(N+72)%256])%256;
    return(idx1==idx2 ? A[idx1] :  A[idx1]+A[idx2] );
}



More information about the cryptography mailing list