简体   繁体   中英

"OverflowError: Python int too large to convert to C long" when casting string to int

Im trying to cast an string input of a very long number to an int and then do an modular exponentiation.

This is for a RSA implementation. I already tried using float() instead of int() but i get "TypeError: pow() 3rd argument not allowed unless all arguments are integers"

def decrypt(msg, d, N):
    msg = msg.split(" ")
    return "".join((chr(pow(float(c), d, N)) for c in msg))

When

msg = "13818406027915767570177183276663402837334180264133730515081837956479150196332208155516968226656035253275466022110094958798976988647806521885207572927244548212706996344142304517884262191059944169644390414979240342977846655748407047120764038830629443176329535057966627835745446617436724307619313808303851980047967232388",
d = 0x1956bc10fbd939e1816fdde264541d9d079d0bba189af8b0ef31ca7c232f625d7820010208709183dcbbaa11e04cd33e81b34886f44a7c3dd7ef12b24b5f2f37db1d6c8fa41b4cb7ece17f5f0b80c8902324909d496d0954f24b6c4875d227adce2baae0100ca8a464014095c3c2fe12018b466eb5fa7704cf43eabb6657afe06c324fba0486f73d9ab825f6ea33c8a5345b85dbd29122df1a6cde0e8c46c623a8d490613d2ef8818e5040073bdefea829a159c4931424597a3dbabb8a9cfd0e1f079292a4c166a0efc858ad356345cf25a34b15ea63028cc79abb2c625774736aff42cafe38e585d507fc445214b846469164ae4c799f4fefb2cb1653e8c09439

and

N = 0xa82f300482d14241106faabcccdb43eeac07eeae5e7b640770b41078c1383f6c72cb1ae10f11418668effb8a27b0cf06bd21c3846116b19fa21d216397f920b94d4a10d12cb5743798182355b8e4d2a9859480d7cd5c45c423b215c5a24619e830c5c128f4e0fad4a057a2f5adb63b069253aec360ea14e703d6e1d3132ba430f68db2a0a15f84f3a2eeb40d42b12cc380c15e2266bf35144a4a0c21d294203c4f5d9eba0b5ae727092cbee52efdce8469cc622f41276e1648c8fb9c8ffde1da802fd035f173d20f3d019e756c4c4d71f4033ef79abbeb5599547e6d7b7352b045da751a4cec46cb5297786d6fc738fbfe3f11a00577700fafd4bdcbac42f79043

it is supposed to return "H"

我发现我做错了什么,我忘记了密钥具有能够加密消息的最小长度,因此提供给 chr() 的数字太大并且无效

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM