Calculate the following using the square-and-multiply algorithm:
$13 = 8 + 4 + 1 = 1101_2$
bit | square | multiply |
---|---|---|
1 | $5^0 = 1$ | $5^1 = 5$ |
1 | $5^2 = 25$ | $5^3 = 125 = 3$ |
0 | $5^6 = 9$ | |
1 | $5^{12} = 81 = 20$ | $5^{13} = 100 = 39$ |
$5^{13} \equiv 39 \pmod{61}$
$34 = 32 + 2 = 100010_2$
bit | square | multiply |
---|---|---|
1 | $1$ | $10$ |
0 | $3$ | |
0 | $9$ | |
0 | $81 = -16$ | |
1 | $16^2 = 256 = 62$ | $620 = 38$ |
0 | $86$ |
38 * 38 = 1444 = 14 * (97 + 3) + 44 = 42 + 44 = 86
114
304
1444
$10^{34} \equiv 86 \pmod{97}$
Calculate the following using the Euclidean algorithm:
a, b, c = a mod b a = k*b + c
b, c, d = b mod c
...
x, y, z = x mod y = 0
gcd(a, b) = y
$a$ | $b$ | $c$ |
---|---|---|
264 | 210 | 54 |
210 | 54 | 48 |
54 | 48 | 6 |
48 | 6 | 0 |
$\gcd(264, 210) = 6$
$a$ | $b$ | $c$ | $a = kb + c$ |
---|---|---|---|
975 | 124 | 107 | $975 = 7 \cdot 124 + 107$ |
124 | 107 | 17 | $124 = 1 \cdot 107 + 17$ |
107 | 17 | 5 | $107 = 6 \cdot 17 + 5$ |
17 | 5 | 2 | $17 = 3 \cdot 5 + 2$ |
5 | 2 | 1 | $5 = 2 \cdot 2 + 1$ |
2 | 1 | 0 | $2 = 2 \cdot 1 + 0$ |
$\gcd(975, 124) = 1$, $975 \bot 124$ (coprime)
$a$ | $b$ | $c$ | $a = kb + c$ |
---|---|---|---|
89 | 55 | 34 | $89 = 1 \cdot 55 + 34$ |
55 | 34 | 21 | $55 = 1 \cdot 34 + 21$ |
34 | 21 | 13 | $34 = 1 \cdot 21 + 13$ |
21 | 13 | 8 | $21 = 1 \cdot 13 + 8$ |
13 | 8 | 5 | $13 = 1 \cdot 8 + 5$ |
8 | 5 | 3 | $8 = 1 \cdot 5 + 3$ |
5 | 3 | 2 | $5 = 1 \cdot 3 + 2$ |
3 | 2 | 1 | $3 = 1 \cdot 2 + 1$ |
$\gcd(89, 55) = 1$
Calculate the following using the extended Euclidean algorithm:
a = 1*a + 0*b a = k*b + c c = a - k*b
b = 0*a + 1*b b = l*c + d d = b - l*c
c = (1 - k*0)*a + (0 - k*1)*b
d = ... * a + ... * b
...
1 = r*a + s*b
a^-1 mod b = r
b^-1 mod a = s
$k$ | $a$ | $r$ | $s$ |
---|---|---|---|
17 | 1 | 0 | |
3 | 0 | 1 | |
5 | 2 | 1 | -5 |
1 | 1 | -1 | 6 |
$k$ | $a$ | $s$ |
---|---|---|
61 | 0 | |
13 | 1 | |
4 | 9 | -4 |
1 | 4 | 5 |
2 | 1 | -14 |
$13^{-1} \bmod{61} = 61 - 14 = 47$
$k$ | $a$ | $s$ |
---|---|---|
97 | 0 | |
10 | 1 | |
9 | 7 | -9 |
1 | 3 | 10 |
2 | 1 | -29 |
$10^{-1} \bmod{97} = 68$
Recall that in the Diffie-Hellman protocol, Alice and Bob first agree on a group element $\alpha$, and then generate secret integers $a$ and $b$, respectively, which they use to compute $\alpha^a$ and $\alpha^b$. After exchanging these values they can compute the shared secret $\alpha^{ab}$. Here, we used the multiplicative notation.
sequenceDiagram
participant Alice
participant Bob
Alice -> Bob: α
Note left of Alice: Generate a
Alice ->> Bob: A = α^a
Note right of Bob: Generate b
Bob ->> Alice: B = α^b
Note left of Alice: Compute k = B^a
Note right of Bob: Compute k = A^b
Group $(G, \circ)$
$\alpha^a = \alpha \circ \alpha \circ \dots \circ \alpha$ ($a$ times)
Examples: $(\mathbb{Z}_n, +_n)$, $(\mathbb{Z}_p^*, *)$