This shows you the differences between two versions of the page.
sasc:laboratoare:03 [2017/03/06 12:42] dan.dragan |
sasc:laboratoare:03 [2017/03/07 15:32] (current) dan.dragan |
||
---|---|---|---|
Line 2: | Line 2: | ||
- | ==== Exercise 1 (2p) ==== | + | ==== Exercise 1 (4p) ==== |
In this exercise we'll try to break a Linear Congruential Generator, that may be used to generate "poor" random numbers. | In this exercise we'll try to break a Linear Congruential Generator, that may be used to generate "poor" random numbers. | ||
Line 103: | Line 103: | ||
</code> | </code> | ||
+ | ==== Exercise 2 (3p) ==== | ||
- | ==== Exercise 2 - LFSR (2p) ==== | + | Let's use the experiment defined earlier as a pseudorandom generator ($\mathsf{PRG}$) as follows: |
+ | - Set a desired output length $n$ | ||
+ | - Obtain a random sequence $R$ of bits of length $n$ (e.g. using the Linear-congruential generator from Exercise 1) | ||
+ | - For each bit $r$ in the random sequence $R$ generated in the previous step, output a bit $b$ as follows: | ||
+ | * if the bit $r$ is $0$, then output a random bit $b \in \{0, 1\}$ | ||
+ | * if the bit $r$ is $1$, then output $1$ | ||
+ | |||
+ | a. Implement the frequency (monobit) test from [[http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf | NIST (see section 2.1)]] and check if a sequence generated by the above $\mathsf{PRG}$ (say $n=100$) seems random or not. | ||
+ | |||
+ | b. Run the test on a random bitstring (e.g. a string such as R used by the above $\mathsf{PRG}$), and compare the result of the test. | ||
+ | |||
+ | If the two results are different across many iterations, this test already gives you an attacker that breaks the $\mathsf{PRG}$. | ||
+ | |||
+ | <note tip>You may use a function like this to generate a random bitstring</note> | ||
+ | <code python> | ||
+ | import random | ||
+ | |||
+ | def get_random_string(n): #generate random bit string | ||
+ | bstr = bin(random.getrandbits(n)).lstrip('0b').zfill(n) | ||
+ | return bstr | ||
+ | </code> | ||
+ | |||
+ | <note tip>Also, in Python you may find the functions sqrt, fabs and erfc from the module math useful</note> | ||
+ | |||
+ | ==== Exercise 3 - LFSR (3p) ==== | ||
In this exercise we'll build a simple Linear Feedback Shift Register (LFSR). LFSRs produce random bit strings with good statistical properties, but are very easy to predict. | In this exercise we'll build a simple Linear Feedback Shift Register (LFSR). LFSRs produce random bit strings with good statistical properties, but are very easy to predict. | ||
Line 127: | Line 152: | ||
Using the above starting state and polynomial, generate $100$ random bits and run the monobit statistical test from the previous exercise to see if their frequency seems random. | Using the above starting state and polynomial, generate $100$ random bits and run the monobit statistical test from the previous exercise to see if their frequency seems random. | ||
- |