Skip to content

CrypTools/Random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random

Random Generators for Cryptography

HashShift

This is a custom PRNG designed at CrypTools

How it works?

We'll use the Swift implementation to describe what we're doing

First, let's take a seed for our generator:

var seed = 12

Then let's hash his String representation:

let hash = String(seed).sha256

Now, we'll take the 10 first characters of the outputed hex digest:

let first = hash.prefix(10)

Now we have a hex representation of a number in a String, let's parse it:

let n = Int(first, radix: 16)

Then, we rotate n like:

let r = (n! >> 13 * seed) % 99371 // for non-swift developers, 'n!' doesn't mean n factorial but the unwrapped value of n

And we change the seed:

seed = (r ^ n! << 2 + n!) % 70937

Finally we output the absolute value as Float of r divided by 99371 to have a number between 0 and 1:

return Float(abs(r)) / 99371

Implementations

Language File
JavaScript random.js
Swift random.swift

Blum Blum Shub

CrypTools didn't created this algorithm, we just found it on the internet

The Blum Blum Shub is a pseudorandom number generator proposed in 1986 by Lenore Blum, Manuel Blum and Michael Shub that is derived from Michael O. Rabin's oblivious transfer mapping.

Blum Blum Shub takes the form:

            2
    x    = x  mod M
     n+1    n

where M = pq is the product of two large primes p and q.

At each step of the algorithm, some output is derived from x[n+1]; the output is commonly either the bit parity of x[n+1] or one or more of the least significant bits of x[n+1].

The seed x[0] should be an integer that is co-prime to M (i.e. p and q are not factors of x[0]) and not 1 or 0.

The two primes, p and q, should both be congruent to 3 (mod 4) (this guarantees that each quadratic residue has one square root which is also a quadratic residue) and gcd(phi(p - 1), phi(q - 1)) should be small (this makes the cycle length large).

In the implementations, p = 5651 and q = 5623.

Implementations

Language File
JavaScript random.js
Swift random.swift

ISAAC

CrypTools didn't created this algorithm, we just found it on the internet

ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. Averaged out, it requires 18.75 machine cycles to generate each 32-bit value. Cycles are guaranteed to be at least 2^40 values long, and they are 2^8295 values long on average. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed.

See the complete description here

Implementations

Language File
JavaScript random.js
C random.c

Marsagalia's PRNG

See the pdf

Implementations

Language File
JavaScript random.js
C random.c

Running the tests

Tests are automatically handled by Travis CI.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Arthur Guiot - Initial work & conception - @arguiot

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

About

Random Generators for Cryptography

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published