Ok so this may be confusing but I'll try to explain it clearly. I have a python script (specifically it converts a bitcoin hexadecimal formatted private key into its public key) in which I can enter in a hexadecimal value and the script will run fine. But when I try to pass it through a variable (posted from an html form), it doesn't work. I'm thinking the output format of this variable isn't correct...maybe because it doesn't blue out the 0x
like as if I were to just input the hexadecimal value into the script.
For example this will make the script run (because i inputted the actual hexadecimal value into the variable privkey
allowing the 0x
part to be turned blue):
# 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...
But when I try passing a variable from a post method input field to the original variable privkey
, it's getting an error stating it is unable to support instances of 'int' or 'str', even though i clearly convert the privkeydecimalform
into the int()
and hex()
functions:
# above section not included.........
@app.route('/elliptic.html', methods=['POST','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,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...
This is the decimal form fyi that I am trying to pass through the privkeydecimalform
variable: 66441505969791109540613028235707613524205333276198781585592012523083977097885