>

$\mathrm{with}\left({\mathrm{RandomTools}}_{\mathrm{BlumBlumShub}}\right)$

$\left[{\mathrm{NewBitGenerator}}{\,}{\mathrm{NewGenerator}}\right]$
 (1) 
The NewBitGenerator command outputs cryptographically secure random bits. It takes as input a random seed S which can be used as a secret key in an encryption protocol.
>

$S\u2254749174032174023174398217651252100347882175301621678436520\:$

>

$B\u2254\mathrm{NewBitGenerator}\left(S\,\mathrm{numbits}\=10\right)\:$

${1}{,}{0}{,}{1}{,}{1}{,}{0}{,}{0}{,}{1}{,}{1}{,}{1}{,}{0}$
 (2) 
${1}{,}{0}{,}{1}{,}{1}{,}{1}{,}{1}{,}{0}{,}{0}{,}{1}{,}{1}$
 (3) 
Suppose Alice wants to send a message M to Bob and suppose Alice wants to encrypt the message so that no one else can read it. Suppose
>

$M\u2254\left[0\,1\,1\,1\,0\,1\,1\,0\,0\,1\,1\,0\,0\,0\,1\,1\,0\,1\,0\,1\right]$

${M}{\u2254}\left[{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{0}{\,}{1}\right]$
 (4) 
is the 20 bit message Alice wants to encrypt. If Alice and Bob both know S then Alice can do the following. First she creates 20 random bits Z as follows.
>

$B\u2254\mathrm{NewBitGenerator}\left(S\,\mathrm{numbits}\=10\right)\:$

>

$Z\u2254\left[B\left(\right)\,B\left(\right)\right]$

${Z}{\u2254}\left[{1}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}\right]$
 (5) 
Now the ciphertext C is formed by adding Z to M modulo 2 (equivalent to an exclusive or of the bits).
>

$C\u2254M\+Z\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}2$

${C}{\u2254}\left[{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}\right]$
 (6) 
Now Alice sends C to Bob. Bob, who knows S, can determine M from C as follows.
>

$B\u2254\mathrm{NewBitGenerator}\left(S\,\mathrm{numbits}\=10\right)\:$

>

$Z\u2254\left[B\left(\right)\,B\left(\right)\right]$

${Z}{\u2254}\left[{1}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}\right]$
 (7) 
>

$C\+Z\phantom{\rule[0.0ex]{0.5em}{0.0ex}}\mathbf{mod}\phantom{\rule[0.0ex]{0.5em}{0.0ex}}2$

$\left[{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{0}{\,}{1}\right]$
 (8) 
$\left[{0}{\,}{1}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{0}{\,}{0}{\,}{1}{\,}{1}{\,}{0}{\,}{1}{\,}{0}{\,}{1}\right]$
 (9) 
The security of the Blum, Blum, and Shub generator depends on the size of the primes used. Choices available are 512, 768, and 1024 bit primes. See NewBitGenerator for further details, examples and other options.