Exponentiation

Last modified: 2023-09-07

Cryptography Math

Basic

We can calculate the exponentiation using '**' operator in Python.

2 ** 4
# 16

6 ** 8
# 1679616

Using Pow Method in Python

The pow method can be used for the exponentiation.

pow(2, 4)
# 2 ** 4 = 16

Modular Exponentiation

In addition, we can find the remainder of dividing a rased value by a specific number.
This may be sometimes used to find the secret key in key derivation functions, etc.

pow(2, 4, 6)
# 2 ** 4 % 6 = 4

Inverse

from Crypto.Util.number import inverse

inverse(3, 10) # 7
pow(3, -1, 10) # 7