# RSA

* `p * q = n`
* Coprime Phi is calculated either by [Euler Totient](https://en.wikipedia.org/wiki/Euler's_totient_function) or [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) via [euclidean algorithm](https://crypto.stanford.edu/pbc/notes/numbertheory/euclid.html) 
* \\(1 < $\phi$ < n \\)
* There is also $\phi$ = (p-1) * (q-1)

* Encryption, public key `e` is a prime between 2 and phi  --> \\( 2 < e < $\phi$ \\)
```python
possible_e = []
for i in range (2, phi):
    if gcd(n, i) == 1 and gcd(phi, i) == 1:
        possible_e.append() 
```

* Decryption, private key `d` --> \\( d * e mod $\phi$ = 1 \\)
```python
possible_d = []
for i in range (phi + 1, phi + foo):
    if i * e mod phi == 1 :
       possible_d.append()
```
* \\( Cipher = msg ** d mod $\phi$ \\)
* \\( Cleartext = cipher ** e mod $\phi$ ) 

## Euklid
```python
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
```

## Links

* [Encryption+Decryption](https://www.cs.drexel.edu/~jpopyack/Courses/CSP/Fa17/notes/10.1_Cryptography/RSA_Express_EncryptDecrypt_v2.html)
