Python 2.7 Code Run on D-Wave

Hi Guys,

 
Actually i have a code in Python 2.7. However, i never used DWave platform. I need to run my code on DWave and for that it requires some modifications which I’m totally unaware of.
 
Could you help me modify my code so i could run it on D-Wave cloud to see how it works? Would really appreciate your help through this. Its very small code by the way. Thanks 
 
Ahmed
0

Comments

4 comments
  • Hello Ahmed,

    Welcome to the Leap community! Please share a short description of your application and a code sample so everyone can take a look.

    I also noticed you've posted this question in multiple places. I believe this is the appropriate location, so I will leave this post active and remove the others. This helps us prevent duplicate content and makes it easier for other users to search for posts in the future.

    1
    Comment actions Permalink
  • Here is my code which i would want to run on DWave Cloud system:

     

    # Below are the public specs for Bitcoin's curve - the secp256k1

    Pcurve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 -1 # The proven prime
    N=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
    Acurve = 0; Bcurve = 7 # These two defines the elliptic curve. y^2 = x^3 + Acurve * x + Bcurve
    Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
    Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
    GPoint = (Gx,Gy)

    #Individual Transaction/Personal Information
    privKey = 12904564038859 #replace with any private key

    def modinv(a,n=Pcurve): #Extended Euclidean Algorithm/'division' in elliptic curves
    lm, hm = 1,0
    low, high = a%n,n
    while low > 1:
    ratio = high/low
    nm, new = hm-lm*ratio, high-low*ratio
    lm, low, hm, high = nm, new, lm, low
    return lm % n

    def ECadd(a,b): # Not true addition.
    LamAdd = ((b[1]-a[1]) * modinv(b[0]-a[0],Pcurve)) % Pcurve
    x = (LamAdd*LamAdd-a[0]-b[0]) % Pcurve
    y = (LamAdd*(a[0]-x)-a[1]) % Pcurve
    return (x,y)

    def ECdouble(a): # This is called point doubling, also invented for EC.
    Lam = ((3*a[0]*a[0]+Acurve) * modinv((2*a[1]),Pcurve)) % Pcurve
    x = (Lam*Lam-2*a[0]) % Pcurve
    y = (Lam*(a[0]-x)-a[1]) % Pcurve
    return (x,y)

    def EccMultiply(GenPoint,ScalarHex): #Double & add. Not true multiplication
    if ScalarHex == 0 or ScalarHex >= N: raise Exception("Invalid Scalar/Private Key")
    ScalarBin = str(bin(ScalarHex))[2:]
    Q=GenPoint
    for i in range (1, len(ScalarBin)): # This is invented EC multiplication.
    Q=ECdouble(Q); # print "DUB", Q[0]; print
    if ScalarBin[i] == "1":
    Q=ECadd(Q,GenPoint); # print "ADD", Q[0]; print
    return (Q)

    print; print "******* Public Key Generation *********";
    print
    PublicKey = EccMultiply(GPoint,privKey)
    r = PublicKey % N;
    print "the private key:";
    print privKey; print
    print r; print
    print "the uncompressed public key (not address):";
    print PublicKey; print
    print "the uncompressed public key (HEX):";
    print "04" + "%064x" % PublicKey[0] + "%064x" % PublicKey[1];
    print;
    print "the official Public Key - compressed:";
    if PublicKey[1] % 2 == 1: # If the Y value for the Public Key is odd.
    print "03"+str(hex(PublicKey[0])[2:-1]).zfill(64)
    else: # Or else, if the Y value is even.
    print "02"+str(hex(PublicKey[0])[2:-1]).zfill(64)

    0
    Comment actions Permalink
  • This is written in Python 2.7 and i believe i need to make some modifications in order to make it run on D-Wave. Would you be able to help me with the modification process? Thanks

     

    Ahmed

    0
    Comment actions Permalink
  • Hi Ahmed,

    The D-Wave quantum computer is a radically different beast from a conventional computer.  Since you're interested in blockchain, and it involves products of huge prime numbers, I think the factoring demo would be a natural place for you to start finding out how the D-Wave works and what it can do.

    https://cloud.dwavesys.com/leap/demos/factoring/intro

    After watching the factoring demo, I suggest studying the Jupyter notebook, which you can find on the following page.

    https://cloud.dwavesys.com/leap/resources/learning-docs

    Cheers,

    Scott

    3
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post