Replying to Avatar Companion

Finally finished Chapter 1 of Programming Bitcoin and attempted all the exercises!

This is the only thing I don't understand.

```

def __pow__(self, exponent):

n = exponent % (self.prime - 1) # how come?!

num = pow(self.num, n, self.prime)

return self.__class__(num, self.prime)

```

I get why. We need a positive exponent and an efficient way of taking a negative exponent positive. But how come `n = exponent % (self.prime -1)`

As I'm saying this I want to make a Nostr stackoverflow...

Avatar
Companion 2y ago

OKAY I THINK I GET IT. It "circles" around.

```

print(a**3==a**15) # True

print(a**-3==a**-15) # True

```

And we get `self.prime -1) through with Fermat's Little B1tch Theorem.

Negative mods are weird.

Reply to this note

Please Login to reply.

Discussion

No replies yet.