Python module module result is incorrect

I am completely at a dead end. I calculated the cipher of number 54 in RSA with the following values:

p is 5; d = 29; n = 145 d = 9; e = 137

Thus, the number 54, encrypted, will be:

54 ^ 137 mod 145

or equivalent in python:

import math
math.pow(54,137)%145

My calculator gives me 24, my python expression gives me 54.0. Python is clearly mistaken, but I have no idea why and how. Try this on your Python installations. My version is 2.5.1, but I also tried on 2.6.5 with the same wrong result.

+3
source share
2 answers
>>> pow(54,137,145)
24

math.pow- floating point. You do not want this. Floating point values ​​have less than 17 digits of useful precision. 54 ** 137 has 237 digits.

+14
source

, math Python C- C, . , math.pow(54,137) 54 ^ 137 64- , , , . Python:

>>> (54 ** 137) % 145
24L
+7

Source: https://habr.com/ru/post/1794312/


All Articles