0

I was solving a problem Called Modular inverting on Crypto Hack the problem states that: if we have 3 * d ≡ 1 mod 13 how can we get d using Fermat Little Theorem

I solved it using basic math but I found a solution that I couldn't understand

'''
Looking again at Fermat's little theorem...
if p is prime, for every integer a:
        pow(a, p) = a mod p
and, if p is prime and a is an integer coprime with p:
        pow(a, p-1) = 1 mod p
We can do some magic like this:
Note: i'll use math notation, so a^b means pow(a,b)
        a^(p-1) = 1 (mod p)
        a^(p-1) * a^-1 = a^-1 (mod p)
        a^(p-2) * a * a^-1 = a^-1 (mod p)
        a^(p-2) * 1 = a^-1 (mod p)
So finally we have:
        a^(p-2) = a^-1 (mod p)
So, doing a^(p-2) and then (mod p) we can achieve
our result
'''

that problem was with the last part when we have $$a^{p-2} ≡ a^{-1}\pmod p \tag{1}$$

all I know that $$a ≡ b\pmod n $$ means: $$a = kn + b$$ which means: $$(a\bmod n) = b$$

applying this to the first equation: $$a^{p-2}\bmod p = a^{-1}$$

I am new to the Congruence so I am sorry if it's a dumb question but can someone explain to me what I am missing here?

Bill Dubuque
  • 282,220

1 Answers1

1

It all results from lil' Fermat, but could be explained in a shorter way:

Remember that Fermat asserts that, for any $a$, not divisible by $p$ (a prime), we have $$a^{p-1}\equiv 1\mod p, $$ which simply means that the remainder of the division by $p$ is $1$. Now $$a^{p-1}=a\cdot a^{p-2}=a^{p-2}\cdot a\equiv 1 \mod p.$$ In other words, by definition, $a^{p-2}$ is the (multiplicative) inverse of $a$ modulo $p$.

Bernard
  • 179,256