我试图将非常长的字符串输入转换为int,然后进行模幂运算。
这是针对RSA实现的。我已经尝试过使用float()而不是int(),但是我收到“ TypeError:pow()除非所有参数都是整数,否则不允许使用第三个参数”
def decrypt(msg, d, N):
msg = msg.split(" ")
return "".join((chr(pow(float(c), d, N)) for c in msg))
何时
msg = "13818406027915767570177183276663402837334180264133730515081837956479150196332208155516968226656035253275466022110094958798976988647806521885207572927244548212706996344142304517884262191059944169644390414979240342977846655748407047120764038830629443176329535057966627835745446617436724307619313808303851980047967232388",
d = 0x1956bc10fbd939e1816fdde264541d9d079d0bba189af8b0ef31ca7c232f625d7820010208709183dcbbaa11e04cd33e81b34886f44a7c3dd7ef12b24b5f2f37db1d6c8fa41b4cb7ece17f5f0b80c8902324909d496d0954f24b6c4875d227adce2baae0100ca8a464014095c3c2fe12018b466eb5fa7704cf43eabb6657afe06c324fba0486f73d9ab825f6ea33c8a5345b85dbd29122df1a6cde0e8c46c623a8d490613d2ef8818e5040073bdefea829a159c4931424597a3dbabb8a9cfd0e1f079292a4c166a0efc858ad356345cf25a34b15ea63028cc79abb2c625774736aff42cafe38e585d507fc445214b846469164ae4c799f4fefb2cb1653e8c09439
和
N = 0xa82f300482d14241106faabcccdb43eeac07eeae5e7b640770b41078c1383f6c72cb1ae10f11418668effb8a27b0cf06bd21c3846116b19fa21d216397f920b94d4a10d12cb5743798182355b8e4d2a9859480d7cd5c45c423b215c5a24619e830c5c128f4e0fad4a057a2f5adb63b069253aec360ea14e703d6e1d3132ba430f68db2a0a15f84f3a2eeb40d42b12cc380c15e2266bf35144a4a0c21d294203c4f5d9eba0b5ae727092cbee52efdce8469cc622f41276e1648c8fb9c8ffde1da802fd035f173d20f3d019e756c4c4d71f4033ef79abbeb5599547e6d7b7352b045da751a4cec46cb5297786d6fc738fbfe3f11a00577700fafd4bdcbac42f79043
应该返回“ H”
答案 0 :(得分:0)
我发现自己在做错什么,我忘记了密钥具有能够加密消息的最小长度,因此给chr()的数字太大而无效