Skip to content

Instantly share code, notes, and snippets.

@pinezapple
Created January 23, 2022 15:05
Show Gist options
  • Save pinezapple/6f784f124baec2b00d5f15da7593e698 to your computer and use it in GitHub Desktop.
Save pinezapple/6f784f124baec2b00d5f15da7593e698 to your computer and use it in GitHub Desktop.
fast-ex file
import sys
a=2
b=103
c=143
def exp_func(x, y, c):
exp = bin(y)
print ("Binary value of b is:",exp)
print ("Bit\tResult")
value = x
for i in range(3, len(exp)):
value = value * value % c
print (i-1,":\t",value,"(square)")
if(exp[i:i+1]=='1'):
value = value*x % c
print (i-1,":\t",value,"(multiply)")
return value
print ("We will calculate a^b")
print ("a=",a)
print ("b=",b)
print ("==== Calculation ====")
res=exp_func(a,b,c)
print ("Result:",res)
print (")===========")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment