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

Viewed 258

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

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.

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.)

Related