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?