问题描述
好的,所以这可能令人困惑,但我会尽力解释清楚。我有一个 python 脚本(特别是它将比特币十六进制格式的私钥转换为其公钥),我可以在其中输入一个十六进制值,脚本将正常运行。但是当我尝试通过变量(从 html 表单发布)传递它时,它不起作用。我认为这个变量的输出格式不正确......也许是因为它没有像我只是将十六进制值输入到脚本中那样将 0x
变蓝。
例如,这将使脚本运行(因为我将实际的十六进制值输入到变量 privkey
中,允许 0x
部分变为蓝色):
# above section not included...
@app.route('/elliptic.html',methods=['POST','GET'])
def teach_elliptic():
if request.method == "POST":
Pcurve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 -1 # The proven prime
Acurve = 0; Bcurve = 7 # These two defines the elliptic curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
GPoint = (Gx,Gy) # Generator Point
N=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
privKey = 0x92e48f4a0a74a0b461155ffc29497247a5053a505a308aaffe14a4b923d2829d
def modinv(a,b=Pcurve): #Extended Euclidean Algorithm/'division' in elliptic curves
lm,hm = 1,0
low,high = a%b,b
while low > 1:
ratio = high//low
nm,new = hm-lm*ratio,high-low*ratio
lm,low,hm,high = nm,new,lm,low
return lm % b
# below section not included...
但是当我尝试将变量从 post 方法输入字段传递到原始变量 privkey
时,它收到一个错误,指出它无法支持“int”或“str”的实例,即使我清楚地将 privkeydecimalform
转换为 int()
和 hex()
函数:
# above section not included.........
@app.route('/elliptic.html','GET'])
def teach_elliptic():
if request.method == "POST":
privkeydecimalform = request.form["decimalform"]
Pcurve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 -1 # The proven prime
Acurve = 0; Bcurve = 7 # These two defines the elliptic curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
GPoint = (Gx,Gy) # Generator Point
N=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
privKey = hex(int(privkeydecimalform))
def modinv(a,low
return lm % b
# below section not included...
这是我试图通过 privkeydecimalform
变量传递的十进制形式:66441505969791109540613028235707613524205333276198781585592012523083977097885
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)