Tiny Diffie-Hellman groups can be searched directly. This lesson recovers Alice's secret by recomputing powers of the public generator.
highlighted = computed this step
Why the toy can be attacked
If p is tiny, an attacker can try exponents in order until a public value appears. The table recomputes g to the k power modulo p for each row.
gkmodp
Target Alice's public value
Alice published A=8. The attacker tries k values until g to k equals that target.
A=8
Read the brute-force rows
The rows show 5, 2, 10, 4, 20, then 8.
g6modp=8
Recover the secret
The hit row recovers Alice's exponent a=6. This is why deployed groups must be huge.
a=6
Summary
The toy discrete log recovers a=6. NOTE: toy-modulus; no-side-channel; no-production; never-roll-your-own. Exact arithmetic on a deliberately tiny toy modulus; real DH uses 2048+ bit groups inside authenticated reviewed protocols.