So I was reading a question on SO and I don't understand the code of the answer it has. It is doing some bit wise operation but i don't know how that works and what is actually going on within the while loop and the need of mod at b2 = (b2*b2) % m
b2 = b
res = 1
while e:
if e & 1:
res = (res * b2) % m
b2 = (b2*b2) % m
e >>= 1
Can anyone help me to understand it ?