Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* Install the Python library ` pycryptodome ` by executing the following in a code cell. ` ` ` ! pip install pycryptodome ` `

* Install the Python library `pycryptodome` by executing the following in a code cell.
```
!pip install pycryptodome
```
* Import some functions we will use by executing the following code. (This will raise an error if `pycryptodome` hasn't been successfully installed.)
```
from Crypto.Util.number import getPrime, getRandomNBitInteger
from sympy.ntheory import n_order
from Lab2_Helper import (
only_letters,
weave,
shift_string,
add_spaces,
to_base_b,
from_base_b
)
```
* Paste in your code defining the `vigenere` function from Lab 1.(It has been included all the necessary imports like `only_letters`, but feel free to add more if your `vigenere` function depends on them.)
* Paste the code defining the `naive_dlog` function.
```
def naive_dlog(g, h, p):
output =1
for i in range(p-1):
output = output*g%p
if output == h:
return i
return None
```
The `getPrime` function imported above takes as input an integer `N` and as output returns a random `N`-bit prime number. (For example, `37=32+4+1` written in binary is `100101`, which is 6 digits, so `37` is a 6-bit prime number. You can verify this by evaluating `to_base_b(37,2)` and checking that the resulting list is length 6. The `from_base_b` function goes in the opposite direction.)
* Choose a prime `p0` using the `getPrime` function. (See the next few instructions to help you decide how large the prime should be.)
* Find a generator `g0` for $(\mathbb{Z}_{p_0})^{*}$.(Hint. Use the `n_order` function that we imported from SymPy. Call `help(n_order)` to see how this function works. What order do we need to have a generator? You will have to do some guessing-and-checking (or better, use a `for` loop, calling `break` when you've found a generator), but it shouldn't take many guesses before you find a generator.)
* Call `naive_dlog(g0,0, p0)`, and time how long it takes using `%%time` at the top of the cell. We already know that no discrete logarithm exists in this case (why?), so the point of this is just to see how long the naive discrete logarithm takes to run in the worst-case scenario.
* We want a prime for which this naive discrete logarithm calculation takes 1-4 seconds. If your prime takes an amount of time outside of this range, then change the values of `p0` and `g0` above until you find values for which it takes 1-4 seconds.
* Again using the getPrime function, find a prime `p` which is `20` bits larger (add, don't multiply) than the prime `p0` you found above.
* As above, find a generator `g` for $(\mathbb{Z}_{p})^{*}$.
* We estimate that multiplying `p0` by `M` will multiply the amount of time the naive discrete logarithm takes by `M`. Using this estimate, how many *days* would you expect the naive discrete logarithm to take for `p`?(Your answer should depend on `p/p0` and on the number of seconds given by your timing computation above. **Do not** try to run the naive discrete logarithm function on `p` directly. Be sure your answer is in days, not in seconds.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions