# Posts Tagged - cryptography

Key Generation

1. Generate two random primes, p and q, e.g p=3, q=11.

2. Compute n = pq, n = 3 * 11 = 33.

3. Compute phi = (p-1)(q-1) = (3-1)(11-1) = 20

4. Choose an integer e, 1 < e < phi, such that gcd(e, phi) = 1, e.g e = 7, gcd(7, 20) = 1

5. Compute the secret exponent d, 1 < d < phi, such that (e * d) mod phi = 1, (7 * d) mod 20 = 1, d = 3

11^37 = ?

37 = 100101 in binary

• 1 -> fist one list number = 11

• 0 -> square = (11)^2

• 0 -> square = ((11)^2)^2

• 1 -> square + multiply = (((11)^2)^2)^2*11

• 0 -> square = ((((11)^2)^2)^2*11)^2

• 1 -> square + multiply = (((((11)^2)^2)^2*11)^2)^2*11

gcd(11, 17) == 1

``````
17 = 11(1) + 6    // 1 is floor(17/11), 6 is 17 mod 11
11 = 6(1) + 5
6 = 5(1) + 1      // done

``````

``````p = prime number (public)
g = modulus (public)

a = Alice private key (private)
b = Bob private key (private)

A = Alice public key (public)
B = Bob public ket = (public)

Sx = Shared key (public)

eA = Eve private key for Alice (private)
eB = Eve private key for Bob (private)
Ea = Spoofed Alice public key will sent to Bob (public)
Eb = Spoofed Bob public key will sent to Alice (public)
``````