Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia power operator ^ returns different value than python pow()

Tags:

julia

i made a rsa-encryption demo to learn julia but ran into a problem. this should be no issue of overflow and all values fit rsa criteria when i check with python code. any pointers are welcome. julia is an awesome language and i would like to figure this out.

check these images to see my problem: Julia Code with Problem Python Verification

like image 729
Baumwolle 25 Avatar asked May 11 '26 10:05

Baumwolle 25


2 Answers

You need BigInt(message)^used_e, and similar. The problem you are seeing is integer overvflow before you convert to BigInt. Note that powermod(BigInt(message), used_e, used_N) will be much faster since it will keep all the intermediate numbers smaller.

like image 67
Oscar Smith Avatar answered May 15 '26 20:05

Oscar Smith


Note that in Julia x % y is a synonym for the rem(x, y) function “from Euclidean division, returning a value of the same sign as x”, whereas for an RSA implementation, you need the mod function instead, where the result has the same sign as y. (But you really actually want powermod over BigInt here for performance.)

like image 41
Markus Kuhn Avatar answered May 15 '26 20:05

Markus Kuhn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!