Processing math: 0%

First time here? Check out the FAQ!

Ask Your Question
0

power_mod strange...

asked 5 years ago

Jingenbl gravatar image

where is the error?

x = 15

z = power_mod(x,3,23) #z=15^3 mod 23

inverse = inverse_mod(3,23) #1/3 mod 23

assert mod(3*inverse,23)==1 #ok

y = power_mod(z,inverse,23) # y = 15^(3/3) = 15

print(y)

18

Thanks a lot to everyone

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 5 years ago

rburing gravatar image

updated 5 years ago

For exponents there is the relation x^a \equiv x^{a \mod \varphi(n)} \pmod n if \gcd(x,n)=1; here \varphi is Euler's phi function, and we use Euler's theorem.

You confused \varphi(n) with n. Here is a correction of your code, using \varphi = {}euler_phi:

x = 15
z = power_mod(x,3,23) #z=15^3 mod 23
inverse = inverse_mod(3,euler_phi(23)) #1/3 mod phi(23)
assert mod(3*inverse,euler_phi(23))==1 #ok
y = power_mod(z,inverse,23) # y = 15^(3/3) = 15
print(y)

Output:

15
Preview: (hide)
link
0

answered 5 years ago

Jingenbl gravatar image

thank you so much. I will study this more closely

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 1,245 times

Last updated: Jan 27 '20