提问人:LilLee 提问时间:10/31/2023 最后编辑:Gino MempinLilLee 更新时间:11/3/2023 访问量:69
无法在 Windows 上安装 gmpy
Can't install gmpy on Windows
问:
我试过,但没有用。pip install gmpy
错误如下:
PS C:\Users\ADMIN\Downloads> pip install gmpy
Collecting gmpy
Using cached gmpy-1.17.zip (147 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: gmpy
Building wheel for gmpy (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for gmpy (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [3 lines of output]
gmpy.c
src/gmpy.c(243): fatal error C1083: Cannot open include file: 'longintrepr.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for gmpy
Failed to build gmpy
ERROR: Could not build wheels for gmpy, which is required to install pyproject.toml-based projects
然而,其他人奏效了。pip install gmpy2
我尝试导入它们:
这是我需要计算的部分:
N = 17740803753336460891508014077951088945415214329359164945595622460861617151883658129377771074141448545977293824812472806768754107334272113784618671425945265453677763300584120796664192793654787317526905676618168560287204392207536711238413377822113265783504873957094131330620182217422910507867161033695120195691266283498385072573721376398480018719760538723050237163598524153522595496137288270407836138586188296538117138982579560625325815068701431157466298638302885600982291990551448117534677697122276691651611734934147801954625280213769902451417946572231015611006746186167211313556716518863585799128114202130873384852581
e = 65537
ct = 7617664236008252568996899627946125782926068188323112773389474654757630578865481085502759186904920518615173703165984894164411436709177950136929724052191922739861682189280802963747906815275683543148623167088950096943169566195634558711652670745197446307315888349532981492405588457559228674864147994684328968321710022127803384848143475788457274558988285904875669797926919759123645348144531804252200718312650929926931919262408975771593313266992606751663814830129337536342634243623652919127335934704778878412649409415730419077839365246227059700689395639431013008985996793686430486195007712091309878718060405038405039494286
a = sqrt(N) +1
b = (a*a) - N # if I use gmpy2 instead of gmpy, the result will be wrong
#p = a - sqrt((b)) gmpy2 return b as a negative number, so I can't calculate p
p = 133194608574583306560585537741344865434566457335756913474195376386565743253745136529892878182973405477415063521701522490974580141634005077732157132519942995782242635825758964371685299620951981666567270659322471350406909271667819474931143113141023059424058315681431599980321513448212682539665160717948701866681
# for this result, I used gmpy in sagemath in Ubuntu.
答:
0赞
BlueBeret
10/31/2023
#1
GMPY 不再维护,您应该使用 .在这种情况下,您需要的是返回 n 平方根的整数部分。gmpy2
gmpy2.isqrt(n)
和 in 之间的区别在于它支持浮点数,但它不能用于密码学中的大数字。isqrt
sqrt
gmpy2
sqrt
源:
评论
0赞
LilLee
11/1/2023
好吧,但似乎 gmpy2.sqrt() 返回了错误的值(不是我预期的值)。我试图解决一个需要计算sqrt(big_num)的CTF挑战,而在Ubuntu中运行良好并返回正确的值,返回一些负数。gmpy.sqrt()
gmpy2.sqrt()
0赞
BlueBeret
11/2/2023
@LilLee你到底想解决什么问题?如果你想找到整数结果,你可以使用 gmpy2.isqrt() (它相当于 gmpy.sqrt(),因为它只接受整数)
0赞
LilLee
11/3/2023
@BlueBeret我已经编辑了问题,添加了有关 RSA 相关挑战的更多详细信息,我不知道 gmpy2.sqrt() 和 gmpy.sqrt() 有什么区别。我尝试了gmpy2.isqrt()并且它起作用了!
0赞
BlueBeret
11/3/2023
@LilLee 很高兴为您提供帮助,我已经更新了我的答案,如果它回答了您的问题,请将其标记为已接受。我也是 ctf 玩家:D
评论