Created
January 23, 2022 15:05
-
-
Save pinezapple/6f784f124baec2b00d5f15da7593e698 to your computer and use it in GitHub Desktop.
fast-ex file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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