# RSA, calculating the value from the lists

I am writing my script to provide me with an RSA public and private key. I am trying to calculate the values of 'e' and 'd' where ed = 1mod64. I know the values will be e=5 and d=13. I have two lists of prime numbers up to 64, I want to multiply these lists together to calculate 'e' and 'd'. I am sure it will involve a while loop so that, while the value is not 65 keep going. I am struggling to write this code however as I am not sure how to get the lists to calculate not in parallel. Apologies if this has been asked but I have been going round in circles for quite some time, if it has been asked please just post the link to it and I shall remove this question.

I'm a fan of the `itertools` module, so here is an example using it.

Python:

``````import itertools
primes = [2, 3, 5, 7]
for p, q in itertools.combinations(primes,2):
print ((p,q))
```
```

Output is:

``````(2, 3)
(2, 5)
(2, 7)
(3, 5)
(3, 7)
(5, 7)
```
```

Python:

``````primes = [2, 3, 5, 7, 11, 13, 17, 19]
for e, d in itertools.combinations(primes,2):
if (e*d) % 64 == 1:
print ((e,d))
```
```

Output:

``````(5,13)
```
```

Note that, in general, this is a terribly inefficient algorithm for finding modular inverses. You should instead use some version of the extended euclidean algorithm for anything larger than toy-sized parameters.