Bitcoin Forum
May 13, 2024, 05:23:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 [14] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 »
  Print  
Author Topic: [ARCHIVE] Bitcoin challenge discusion  (Read 28993 times)
almightyruler
Legendary
*
Offline Offline

Activity: 2268
Merit: 1092


View Profile
September 06, 2019, 03:50:23 AM
 #261

He is an example that shows that 57feRe code works well. Nice tool for fast recovery of partial private key loss when public key is known using one core CPU.

PUBKEY      03B5406C79568685D9ECFC547DFF8CD373A6417ED259007215AAF52442C808EA7A
PVKRANGE 6972ACF5B21F4C39E5E521CEAAB9506FADEDBD65C766B8DDAFA2B00000000000   6972ACF5B21F4C39E5E521CEAAB9506FADEDBD65C766B8DDAFA2C00000000000

I presume you've modified the source to specify arbitrary pubkey, plus private key ranges? I don't understand the math, and Python is kind of a read-only language for me, so I can't really go much further than the original example code.  Grin Any plans to release your changes?
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
1715621008
Hero Member
*
Offline Offline

Posts: 1715621008

View Profile Personal Message (Offline)

Ignore
1715621008
Reply with quote  #2

1715621008
Report to moderator
PrivatePerson
Member
**
Offline Offline

Activity: 173
Merit: 12


View Profile
September 06, 2019, 04:56:37 AM
 #262

57fe script and Telariust searches for a private key only in the indicated bit range? I changed the name of the 16 bit key to 51 and nothing was found in a few hours.
almightyruler
Legendary
*
Offline Offline

Activity: 2268
Merit: 1092


View Profile
September 06, 2019, 05:06:32 AM
 #263

57fe script and Telariust searches for a private key only in the indicated bit range? I changed the name of the 16 bit key to 51 and nothing was found in a few hours.

There is this line in two versions of the code which seem to suggest the start of the privkey range is derived from the number of bits (the variable "problem" contains the number of bits) :

Code:
search_range = 2**(problem-1)

So if problem=32, search_range will be 2^31 = 2147483648 decimal or 0x80000000

... but, I cannot see the variable search_range used anywhere else in the code. I'm not a Python programmer so I may be missing something obvious, or perhaps it really is a calculation where the result is never used.
Firebox
Jr. Member
*
Offline Offline

Activity: 59
Merit: 3


View Profile
September 06, 2019, 06:12:32 AM
 #264

57fe script and Telariust searches for a private key only in the indicated bit range? I changed the name of the 16 bit key to 51 and nothing was found in a few hours.

There is this line in two versions of the code which seem to suggest the start of the privkey range is derived from the number of bits (the variable "problem" contains the number of bits) :

Code:
search_range = 2**(problem-1)

So if problem=32, search_range will be 2^31 = 2147483648 decimal or 0x80000000

... but, I cannot see the variable search_range used anywhere else in the code. I'm not a Python programmer so I may be missing something obvious, or perhaps it really is a calculation where the result is never used.
I think you are wrong. This defined name "search_range" is not used by any function or in any calculation, so you may just comment it and nothing is going to happened.
almightyruler
Legendary
*
Offline Offline

Activity: 2268
Merit: 1092


View Profile
September 06, 2019, 07:16:16 AM
Last edit: September 06, 2019, 07:44:46 AM by almightyruler
 #265

... but, I cannot see the variable search_range used anywhere else in the code. I'm not a Python programmer so I may be missing something obvious, or perhaps it really is a calculation where the result is never used.
I think you are wrong. This defined name "search_range" is not used by any function or in any calculation, so you may just comment it and nothing is going to happened.

That actually means I'm correct, because I stated that even though the calculation seems to be related to generating a privkey range, the result is unused.

To go back to PrivatePerson's question, this version lets you specify the bits and pubkey on the commandline. I tried some different pubkeys with larger bit sizes and it still finds them: https://bitcointalk.org/index.php?topic=5166284.msg52318676#msg52318676

$ ./pollard_kangaroo_new.py -h
[################################################]
[# ECDSA Pollard-kangaroo PrivKey Recovery Tool #]
[#          based on code by 57fe 2019          #]
[#                  singlecore                  #]
[################################################]
[usage] ./pollard_kangaroo_new.py [bits] [pubkey]
        ./pollard_kangaroo_new.py 32
        ./pollard_kangaroo_new.py 32 0209c58240e50e3ba3f833c82655e8725c037a2294e14cf5d73a5df8d56159de69


Edit: I thought the commandline parameter [bits] was used to generate a mask to match the puzzle transaction (eg 16 = lower 16 bits random, upper 240 bits set to 0), but since it still finds keys with the lower 32 bits used when [bits] is set to 31, 30, even 16, it must be for something else. I'm going to fade into the background again until I understand this better.
racminer
Member
**
Offline Offline

Activity: 242
Merit: 17


View Profile
September 06, 2019, 08:22:14 AM
 #266

Here is the code with my changes
Code:

import time
import random
import gmpy2
import math
import sys

modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
order  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

PG = Point(Gx,Gy)
Z = Point(0,0) # zero-point, infinite in real x,y - plane

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)

def rev(b, n = modulo):
    while b < 0:
        b += modulo
    g, x, _ = egcd(b, n)
    if g == 1:
        return x % n
       
def mul2(P, p = modulo):
    R = Point()
#    c = 3*P.x*P.x*rev(2*P.y, p) % p
    c = 3*P.x*P.x*gmpy2.invert(2*P.y, p) % p
    R.x = (c*c-2*P.x) % p
    R.y = (c*(P.x - R.x)-P.y) % p
    return R

def add(P, Q, p = modulo):
    R = Point()
    dx = Q.x - P.x
    dy = Q.y - P.y   
    c = dy * gmpy2.invert(dx, p) % p     
    #c = dy * rev(dx, p) % p     
    R.x = (c*c - P.x - Q.x) % p
    R.y = (c*(P.x - R.x) - P.y) % p
    return R # 6 sub, 3 mul, 1 inv

def mulk(k, P = PG, p = modulo):
    if k == 0: return Z
    elif k == 1: return P
    elif (k % 2 == 0):
        return mulk(k/2, mul2(P, p), p)
    else:
        return add(P, mulk( (k-1)/2, mul2(P, p), p), p)

def X2Y(X, p = modulo):
    if p % 4 != 3:
        print ('prime must be 3 modulo 4')
        return 0
    X = (X**3+7)%p
    pw = (p + 1) // 4
    Y = 1
    for w in range(256):
        if (pw >> w) & 1 == 1:
            tmp = X
            for k in range(w):
                tmp = (tmp**2)%p
            Y *= tmp
            Y %= p
    return Y

def comparator():
    A, Ak, B, Bk = [], [], [], []
    with open('tame.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            A.append(a)
            Ak.append(b)
    with open('wild.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            B.append(a)
            Bk.append(b)
    result = list(set(A) & set(B))
    if len(result) > 0:
        sol_kt = A.index(result[0])
        sol_kw = B.index(result[0])
        print ('total time: %.2f sec' % (time.time()-starttime))
        d = Ak[sol_kt] - Bk[sol_kw]
        print ('SOLVED: %64X' % d + '\n')
        file = open("results.txt",'a')
        file.write(('%X'%(Ak[sol_kt] - Bk[sol_kw])) + "\n")
        file.write("---------------\n")
        file.close()
        return True
    else:
        return False

def check(P, Pindex, DP_rarity, file2save):
    if P.x % (DP_rarity) == 0:
        file = open(file2save,'a')
        file.write(('%064X %064X'%(P.x,Pindex)) + "\n")
        file.close()
        return comparator()
    else:
        return False
   
P = [PG]
for k in range(255): P.append(mul2(P[k]))   
print ('P-table prepared')   

def search(a,b):
    global solved
    s=(a+b)>>1
    d=(b-a)
    problem=int(math.log(d,2))
#    print(a,b,s,d,'\n')
    DP_rarity = 1 << ((problem -  2*kangoo_power)//2 - 2)
    hop_modulo = ((problem-1)// 2) + kangoo_power
    T, t, dt = [], [], []
    W, w, dw = [], [], []
    for k in range(Nt):
        qtf= s
        qtr= random.randint(1,d)
 #       print('tame\n',qtf,qtr)
        qt=qtf+qtr
        t.append(qt) 
        T.append(mulk(t[k]))
        dt.append(0)
    for k in range(Nw):
        qw=(random.randint(1, d))
  #      print('wild\n',qw)
        w.append(qw)
        W.append(add(W0,mulk(w[k])))
        dw.append(0)
    print ('tame and wild herds are prepared')
    oldtime = time.time()
    starttime = oldtime
    Hops, Hops_old = 0, 0
    t0 = time.time()
    oldtime = time.time()
    starttime = oldtime
    while (1):
        for k in range(Nt):
            Hops += 1
            pw = T[k].x % hop_modulo
            dt[k] = 1 << pw
            solved = check(T[k], t[k], DP_rarity, "tame.txt")
            if solved: break
            t[k] += dt[k]
            T[k] = add(P[pw], T[k])
        if solved: break           
        for k in range(Nw):
            Hops += 1
            pw = W[k].x % hop_modulo
            dw[k] = 1 << pw
            solved = check(W[k], w[k], DP_rarity, "wild.txt")
            if solved: break
            w[k] += dw[k]
            W[k] = add(P[pw], W[k])
        if solved: break
        t1 = time.time()
        if (t1-t0) > 5:
            print ('%.3f h/s'%((Hops-Hops_old)/(t1-t0)))
            t0 = t1
            Hops_old = Hops
    hops_list.append(Hops)       
    print ('Hops:', Hops)       
    return 'sol. time: %.2f sec' % (time.time()-starttime)   

s=sys.argv[1]
sa = sys.argv[2]
sb = sys.argv[3]
sk = sys.argv[4]
a = int(sa, 16)
b = int(sb, 16)
kangoo_power = int(sk, 10)
Nt = Nw = 2**kangoo_power
X = int(s, 16)
Y = X2Y(X % (2**256))
if Y % 2 != (X >> 256) % 2: Y = modulo - Y
X = X % (2**256)
W0 = Point(X,Y)
starttime = oldtime = time.time()
Hops = 0
random.seed()

hops_list = []

solved = False
open("tame.txt",'w').close()
open("wild.txt",'w').close()
search(a,b)

Example (case 32)

python kang.py 0387dc70db1806cd9a9a76637412ec11dd998be666584849b3185f7f9313c8fd28 80000000 FFFFFFFF 3

(the last number 3 is the kangooro_power)

P-table prepared
tame and wild herds are prepared
total time: 0.21 sec
SOLVED:                                                         7D4FE747

('Hops:', 23072)
brainless
Member
**
Offline Offline

Activity: 316
Merit: 34


View Profile
September 06, 2019, 02:30:47 PM
 #267

Here is the code with my changes
Code:

import time
import random
import gmpy2
import math
import sys

modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
order  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

PG = Point(Gx,Gy)
Z = Point(0,0) # zero-point, infinite in real x,y - plane

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)

def rev(b, n = modulo):
    while b < 0:
        b += modulo
    g, x, _ = egcd(b, n)
    if g == 1:
        return x % n
       
def mul2(P, p = modulo):
    R = Point()
#    c = 3*P.x*P.x*rev(2*P.y, p) % p
    c = 3*P.x*P.x*gmpy2.invert(2*P.y, p) % p
    R.x = (c*c-2*P.x) % p
    R.y = (c*(P.x - R.x)-P.y) % p
    return R

def add(P, Q, p = modulo):
    R = Point()
    dx = Q.x - P.x
    dy = Q.y - P.y   
    c = dy * gmpy2.invert(dx, p) % p     
    #c = dy * rev(dx, p) % p     
    R.x = (c*c - P.x - Q.x) % p
    R.y = (c*(P.x - R.x) - P.y) % p
    return R # 6 sub, 3 mul, 1 inv

def mulk(k, P = PG, p = modulo):
    if k == 0: return Z
    elif k == 1: return P
    elif (k % 2 == 0):
        return mulk(k/2, mul2(P, p), p)
    else:
        return add(P, mulk( (k-1)/2, mul2(P, p), p), p)

def X2Y(X, p = modulo):
    if p % 4 != 3:
        print ('prime must be 3 modulo 4')
        return 0
    X = (X**3+7)%p
    pw = (p + 1) // 4
    Y = 1
    for w in range(256):
        if (pw >> w) & 1 == 1:
            tmp = X
            for k in range(w):
                tmp = (tmp**2)%p
            Y *= tmp
            Y %= p
    return Y

def comparator():
    A, Ak, B, Bk = [], [], [], []
    with open('tame.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            A.append(a)
            Ak.append(b)
    with open('wild.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            B.append(a)
            Bk.append(b)
    result = list(set(A) & set(B))
    if len(result) > 0:
        sol_kt = A.index(result[0])
        sol_kw = B.index(result[0])
        print ('total time: %.2f sec' % (time.time()-starttime))
        d = Ak[sol_kt] - Bk[sol_kw]
        print ('SOLVED: %64X' % d + '\n')
        file = open("results.txt",'a')
        file.write(('%X'%(Ak[sol_kt] - Bk[sol_kw])) + "\n")
        file.write("---------------\n")
        file.close()
        return True
    else:
        return False

def check(P, Pindex, DP_rarity, file2save):
    if P.x % (DP_rarity) == 0:
        file = open(file2save,'a')
        file.write(('%064X %064X'%(P.x,Pindex)) + "\n")
        file.close()
        return comparator()
    else:
        return False
   
P = [PG]
for k in range(255): P.append(mul2(P[k]))   
print ('P-table prepared')   

def search(a,b):
    global solved
    s=(a+b)>>1
    d=(b-a)
    problem=int(math.log(d,2))
#    print(a,b,s,d,'\n')
    DP_rarity = 1 << ((problem -  2*kangoo_power)//2 - 2)
    hop_modulo = ((problem-1)// 2) + kangoo_power
    T, t, dt = [], [], []
    W, w, dw = [], [], []
    for k in range(Nt):
        qtf= s
        qtr= random.randint(1,d)
 #       print('tame\n',qtf,qtr)
        qt=qtf+qtr
        t.append(qt) 
        T.append(mulk(t[k]))
        dt.append(0)
    for k in range(Nw):
        qw=(random.randint(1, d))
  #      print('wild\n',qw)
        w.append(qw)
        W.append(add(W0,mulk(w[k])))
        dw.append(0)
    print ('tame and wild herds are prepared')
    oldtime = time.time()
    starttime = oldtime
    Hops, Hops_old = 0, 0
    t0 = time.time()
    oldtime = time.time()
    starttime = oldtime
    while (1):
        for k in range(Nt):
            Hops += 1
            pw = T[k].x % hop_modulo
            dt[k] = 1 << pw
            solved = check(T[k], t[k], DP_rarity, "tame.txt")
            if solved: break
            t[k] += dt[k]
            T[k] = add(P[pw], T[k])
        if solved: break           
        for k in range(Nw):
            Hops += 1
            pw = W[k].x % hop_modulo
            dw[k] = 1 << pw
            solved = check(W[k], w[k], DP_rarity, "wild.txt")
            if solved: break
            w[k] += dw[k]
            W[k] = add(P[pw], W[k])
        if solved: break
        t1 = time.time()
        if (t1-t0) > 5:
            print ('%.3f h/s'%((Hops-Hops_old)/(t1-t0)))
            t0 = t1
            Hops_old = Hops
    hops_list.append(Hops)       
    print ('Hops:', Hops)       
    return 'sol. time: %.2f sec' % (time.time()-starttime)   

s=sys.argv[1]
sa = sys.argv[2]
sb = sys.argv[3]
sk = sys.argv[4]
a = int(sa, 16)
b = int(sb, 16)
kangoo_power = int(sk, 10)
Nt = Nw = 2**kangoo_power
X = int(s, 16)
Y = X2Y(X % (2**256))
if Y % 2 != (X >> 256) % 2: Y = modulo - Y
X = X % (2**256)
W0 = Point(X,Y)
starttime = oldtime = time.time()
Hops = 0
random.seed()

hops_list = []

solved = False
open("tame.txt",'w').close()
open("wild.txt",'w').close()
search(a,b)

Example (case 32)

python kang.py 0387dc70db1806cd9a9a76637412ec11dd998be666584849b3185f7f9313c8fd28 80000000 FFFFFFFF 3

(the last number 3 is the kangooro_power)

P-table prepared
tame and wild herds are prepared
total time: 0.21 sec
SOLVED:                                                         7D4FE747

('Hops:', 23072)


 python 2.py 03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 0xaf55fc59c335c8e0000000000 0xaf55fc59c335c8f0000000000 3
P-table prepared
tame and wild herds are prepared
220012.055 h/s
229034.780 h/s
total time: 11.90 sec
SOLVED:                                        AF55FC59C335C8EC67ED24826

('Hops:', 2691957)

13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
Firebox
Jr. Member
*
Offline Offline

Activity: 59
Merit: 3


View Profile
September 06, 2019, 02:48:09 PM
 #268

python 2.py 03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 0xaf55fc59c335c8e0000000000 0xaf55fc59c335c8f0000000000 3
P-table prepared
tame and wild herds are prepared
220012.055 h/s
229034.780 h/s
total time: 11.90 sec
SOLVED:                                        AF55FC59C335C8EC67ED24826

('Hops:', 2691957)

Very narrow range was choosen, that's why so fast. Try at least this one:
03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 cccccccccccccccccccccccb5 e666666666666666666666647 8
(addr #100 ragne 30% -> 40%, as the PKEY is located at ~37% position)

---------

Your speed is impressive ))). Could you share your script? Or it was unchanged?
blueteam09
Full Member
***
Offline Offline

Activity: 664
Merit: 100


📱 CARTESI 📱 INFRASTRUCTURE FOR SCA


View Profile
September 06, 2019, 03:01:50 PM
 #269

I am excited to read your article. I was inquisitive and wanted to participate in this challenge. But after I read the comments from different people. I realise that this is harder than I imagined, we can't search manually. This is only suitable for coders because they can create bots with alternative human tasks.

brainless
Member
**
Offline Offline

Activity: 316
Merit: 34


View Profile
September 06, 2019, 03:51:16 PM
 #270

python 2.py 03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 0xaf55fc59c335c8e0000000000 0xaf55fc59c335c8f0000000000 3
P-table prepared
tame and wild herds are prepared
220012.055 h/s
229034.780 h/s
total time: 11.90 sec
SOLVED:                                        AF55FC59C335C8EC67ED24826

('Hops:', 2691957)

Very narrow range was choosen, that's why so fast. Try at least this one:
03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 cccccccccccccccccccccccb5 e666666666666666666666647 8
(addr #100 ragne 30% -> 40%, as the PKEY is located at ~37% position)

---------

Your speed is impressive ))). Could you share your script? Or it was unchanged?
unchanged
if i run 2 script in 2 difrent folder speed for each script is
220012.055 h/s
229034.780 h/s
if only 1 script run, speed is 238000 h/s

13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
Firebox
Jr. Member
*
Offline Offline

Activity: 59
Merit: 3


View Profile
September 06, 2019, 04:15:22 PM
 #271

python 2.py 03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 0xaf55fc59c335c8e0000000000 0xaf55fc59c335c8f0000000000 3
P-table prepared
tame and wild herds are prepared
220012.055 h/s
229034.780 h/s
total time: 11.90 sec
SOLVED:                                        AF55FC59C335C8EC67ED24826

('Hops:', 2691957)

Very narrow range was choosen, that's why so fast. Try at least this one:
03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 cccccccccccccccccccccccb5 e666666666666666666666647 8
(addr #100 ragne 30% -> 40%, as the PKEY is located at ~37% position)

---------

Your speed is impressive ))). Could you share your script? Or it was unchanged?
unchanged
if i run 2 script in 2 difrent folder speed for each script is
220012.055 h/s
229034.780 h/s
if only 1 script run, speed is 238000 h/s

What is your CPU and what is CPU locks do you use (if any)?
racminer
Member
**
Offline Offline

Activity: 242
Merit: 17


View Profile
September 06, 2019, 04:16:38 PM
 #272

Here is the code with my changes
Code:

import time
import random
import gmpy2
import math
import sys

modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
order  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

PG = Point(Gx,Gy)
Z = Point(0,0) # zero-point, infinite in real x,y - plane

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)

def rev(b, n = modulo):
    while b < 0:
        b += modulo
    g, x, _ = egcd(b, n)
    if g == 1:
        return x % n
       
def mul2(P, p = modulo):
    R = Point()
#    c = 3*P.x*P.x*rev(2*P.y, p) % p
    c = 3*P.x*P.x*gmpy2.invert(2*P.y, p) % p
    R.x = (c*c-2*P.x) % p
    R.y = (c*(P.x - R.x)-P.y) % p
    return R

def add(P, Q, p = modulo):
    R = Point()
    dx = Q.x - P.x
    dy = Q.y - P.y   
    c = dy * gmpy2.invert(dx, p) % p     
    #c = dy * rev(dx, p) % p     
    R.x = (c*c - P.x - Q.x) % p
    R.y = (c*(P.x - R.x) - P.y) % p
    return R # 6 sub, 3 mul, 1 inv

def mulk(k, P = PG, p = modulo):
    if k == 0: return Z
    elif k == 1: return P
    elif (k % 2 == 0):
        return mulk(k/2, mul2(P, p), p)
    else:
        return add(P, mulk( (k-1)/2, mul2(P, p), p), p)

def X2Y(X, p = modulo):
    if p % 4 != 3:
        print ('prime must be 3 modulo 4')
        return 0
    X = (X**3+7)%p
    pw = (p + 1) // 4
    Y = 1
    for w in range(256):
        if (pw >> w) & 1 == 1:
            tmp = X
            for k in range(w):
                tmp = (tmp**2)%p
            Y *= tmp
            Y %= p
    return Y

def comparator():
    A, Ak, B, Bk = [], [], [], []
    with open('tame.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            A.append(a)
            Ak.append(b)
    with open('wild.txt') as f:
        for line in f:
            L = line.split()
            a = int(L[0],16)
            b = int(L[1],16)
            B.append(a)
            Bk.append(b)
    result = list(set(A) & set(B))
    if len(result) > 0:
        sol_kt = A.index(result[0])
        sol_kw = B.index(result[0])
        print ('total time: %.2f sec' % (time.time()-starttime))
        d = Ak[sol_kt] - Bk[sol_kw]
        print ('SOLVED: %64X' % d + '\n')
        file = open("results.txt",'a')
        file.write(('%X'%(Ak[sol_kt] - Bk[sol_kw])) + "\n")
        file.write("---------------\n")
        file.close()
        return True
    else:
        return False

def check(P, Pindex, DP_rarity, file2save):
    if P.x % (DP_rarity) == 0:
        file = open(file2save,'a')
        file.write(('%064X %064X'%(P.x,Pindex)) + "\n")
        file.close()
        return comparator()
    else:
        return False
   
P = [PG]
for k in range(255): P.append(mul2(P[k]))   
print ('P-table prepared')   

def search(a,b):
    global solved
    s=(a+b)>>1
    d=(b-a)
    problem=int(math.log(d,2))
#    print(a,b,s,d,'\n')
    DP_rarity = 1 << ((problem -  2*kangoo_power)//2 - 2)
    hop_modulo = ((problem-1)// 2) + kangoo_power
    T, t, dt = [], [], []
    W, w, dw = [], [], []
    for k in range(Nt):
        qtf= s
        qtr= random.randint(1,d)
 #       print('tame\n',qtf,qtr)
        qt=qtf+qtr
        t.append(qt) 
        T.append(mulk(t[k]))
        dt.append(0)
    for k in range(Nw):
        qw=(random.randint(1, d))
  #      print('wild\n',qw)
        w.append(qw)
        W.append(add(W0,mulk(w[k])))
        dw.append(0)
    print ('tame and wild herds are prepared')
    oldtime = time.time()
    starttime = oldtime
    Hops, Hops_old = 0, 0
    t0 = time.time()
    oldtime = time.time()
    starttime = oldtime
    while (1):
        for k in range(Nt):
            Hops += 1
            pw = T[k].x % hop_modulo
            dt[k] = 1 << pw
            solved = check(T[k], t[k], DP_rarity, "tame.txt")
            if solved: break
            t[k] += dt[k]
            T[k] = add(P[pw], T[k])
        if solved: break           
        for k in range(Nw):
            Hops += 1
            pw = W[k].x % hop_modulo
            dw[k] = 1 << pw
            solved = check(W[k], w[k], DP_rarity, "wild.txt")
            if solved: break
            w[k] += dw[k]
            W[k] = add(P[pw], W[k])
        if solved: break
        t1 = time.time()
        if (t1-t0) > 5:
            print ('%.3f h/s'%((Hops-Hops_old)/(t1-t0)))
            t0 = t1
            Hops_old = Hops
    hops_list.append(Hops)       
    print ('Hops:', Hops)       
    return 'sol. time: %.2f sec' % (time.time()-starttime)   

s=sys.argv[1]
sa = sys.argv[2]
sb = sys.argv[3]
sk = sys.argv[4]
a = int(sa, 16)
b = int(sb, 16)
kangoo_power = int(sk, 10)
Nt = Nw = 2**kangoo_power
X = int(s, 16)
Y = X2Y(X % (2**256))
if Y % 2 != (X >> 256) % 2: Y = modulo - Y
X = X % (2**256)
W0 = Point(X,Y)
starttime = oldtime = time.time()
Hops = 0
random.seed()

hops_list = []

solved = False
open("tame.txt",'w').close()
open("wild.txt",'w').close()
search(a,b)

Example (case 32)

python kang.py 0387dc70db1806cd9a9a76637412ec11dd998be666584849b3185f7f9313c8fd28 80000000 FFFFFFFF 3

(the last number 3 is the kangooro_power)

P-table prepared
tame and wild herds are prepared
total time: 0.21 sec
SOLVED:                                                         7D4FE747

('Hops:', 23072)


 python 2.py 03d2063d40402f030d4cc71331468827aa41a8a09bd6fd801ba77fb64f8e67e617 0xaf55fc59c335c8e0000000000 0xaf55fc59c335c8f0000000000 3
P-table prepared
tame and wild herds are prepared
220012.055 h/s
229034.780 h/s
total time: 11.90 sec
SOLVED:                                        AF55FC59C335C8EC67ED24826

('Hops:', 2691957)


Nice

I see you reproduce the example I mentioned here https://bitcointalk.org/index.php?topic=5173445.msg52376505#msg52376505
(If you are using windows, you might get the wrong answer for case > 60 bit)
PietCoin97
Jr. Member
*
Offline Offline

Activity: 91
Merit: 3


View Profile
September 06, 2019, 04:58:42 PM
 #273

Can you add multithreading to this code ?
brainless
Member
**
Offline Offline

Activity: 316
Merit: 34


View Profile
September 06, 2019, 06:09:40 PM
 #274

Can you add multithreading to this code ?

time is not for multithreading, time is for cuda

13sXkWqtivcMtNGQpskD78iqsgVy9hcHLF
almightyruler
Legendary
*
Offline Offline

Activity: 2268
Merit: 1092


View Profile
September 07, 2019, 02:48:31 AM
Last edit: September 07, 2019, 05:29:59 AM by almightyruler
 #275

For those of you that are interested in experimenting or benchmarking, this version of the code has an interesting feature: if you specify bits (but not the pubkey) on the commandline, it will generate a random privkey/pubkey pair, and then it uses the pubkey only to derive the privkey. It also verifies that the result matches the original privkey. Note you need the coincurve module installed.

https://bitcointalk.org/index.php?topic=5166284.msg52318676#msg52318676

I wrote a script to benchmark bit sizes from 16 to 50 bits:


bits     avgjump      avgtime
-----------------------------
16   |      2222 |    0.0 sec
17   |       685 |    0.0 sec
18   |      1410 |    0.0 sec
19   |      1760 |    0.0 sec
20   |      2471 |    0.0 sec
21   |     11794 |    0.1 sec
22   |     33504 |    0.4 sec
23   |      5848 |    0.1 sec
24   |     33151 |    0.4 sec
25   |    115165 |    1.3 sec
26   |     32936 |    0.4 sec
27   |     21554 |    0.2 sec
28   |     65202 |    0.8 sec
29   |     95825 |    1.1 sec
30   |     83395 |    1.0 sec
31   |    118533 |    1.3 sec
32   |    298726 |    3.4 sec
33   |   1494556 |   16.5 sec
34   |    922811 |   10.2 sec
35   |   3500772 |   40.1 sec
36   |    530865 |    6.1 sec
37   |    874350 |   10.2 sec
38   |   2391518 |   27.8 sec
39   |   1733346 |   19.8 sec
40   |  26815651 |  294.5 sec
41   |   5564319 |   58.2 sec
42   |   6209964 |   64.7 sec
43   |  44672620 |  483.5 sec
44   |   8790286 |   96.7 sec
45   |  77312665 | 1045.7 sec
46   |  34559558 |  478.5 sec
47   |  24016039 |  329.6 sec
48   |  60846064 |  828.8 sec
49   | 127443507 | 1706.6 sec
50   |   ...


(Remember, these are based on randomly generated privkeys, not the puzzle transactions)

I would expect a lot of noise at low bit lengths, but even once there's a lot more work done each run, there's still some large variations (eg #44 versus #45)

The server is fairly heavily loaded so the average jumps is probably a better metric than time period, but even then it's not very useful since the number of jumps varies so much from run to run. I thought it may still be interesting to post the results.
Firebox
Jr. Member
*
Offline Offline

Activity: 59
Merit: 3


View Profile
September 07, 2019, 02:45:37 PM
 #276

Well known 57fe's python script runs using only one core - that's the fact. I have added this code in very beginning of the code the following part of the code:
Code:
import multiprocessing as mp
import psutil
def spawn():
    procs = list()
    n_cpus = psutil.cpu_count()
    for cpu in range(n_cpus):
        affinity = [cpu]
        d = dict(affinity=affinity)
        p = mp.Process(target=run_child, kwargs=d)
        p.start()
        procs.append(p)
    for p in procs:
        p.join()
        print('joined')

def run_child(affinity):
    proc = psutil.Process()  # get self pid
    print('PID: {pid}'.format(pid=proc.pid))
    aff = proc.cpu_affinity()
    print('Affinity before: {aff}'.format(aff=aff))
    proc.cpu_affinity(affinity)
    aff = proc.cpu_affinity()
    print('Affinity after: {aff}'.format(aff=aff))
and supposed that that the scrips will use all cores and it actually does, but the speed drops down to ~60k h/s.
Can any one help to understand why it is? And how to improve the speed of this script?
racminer
Member
**
Offline Offline

Activity: 242
Merit: 17


View Profile
September 07, 2019, 03:05:47 PM
Last edit: September 07, 2019, 03:17:59 PM by racminer
 #277

Well known 57fe's python script runs using only one core - that's the fact. I have added this code in very beginning of the code the following part of the code:
Code:
import multiprocessing as mp
import psutil
def spawn():
    procs = list()
    n_cpus = psutil.cpu_count()
    for cpu in range(n_cpus):
        affinity = [cpu]
        d = dict(affinity=affinity)
        p = mp.Process(target=run_child, kwargs=d)
        p.start()
        procs.append(p)
    for p in procs:
        p.join()
        print('joined')

def run_child(affinity):
    proc = psutil.Process()  # get self pid
    print('PID: {pid}'.format(pid=proc.pid))
    aff = proc.cpu_affinity()
    print('Affinity before: {aff}'.format(aff=aff))
    proc.cpu_affinity(affinity)
    aff = proc.cpu_affinity()
    print('Affinity after: {aff}'.format(aff=aff))
and supposed that that the scrips will use all cores and it actually does, but the speed drops down to ~60k h/s.
Can any one help to understand why it is? And how to improve the speed of this script?

This header alone in not enough to make the reste of the code work with more than one core !
 
Also
n_cpus = psutil.cpu_count() will probably give you the number of logical cores which is usually twice the number of physical cores (depends on what is your CPU).

you might try :
n_cpus = psutil.cpu_count() >> 1  
in principal, you'll get more speed per core

What cpu do you have?
Firebox
Jr. Member
*
Offline Offline

Activity: 59
Merit: 3


View Profile
September 07, 2019, 04:59:24 PM
Last edit: September 07, 2019, 05:21:31 PM by Firebox
 #278

Well known 57fe's python script runs using only one core - that's the fact. I have added this code in very beginning of the code the following part of the code:
Code:
import multiprocessing as mp
import psutil
def spawn():
    procs = list()
    n_cpus = psutil.cpu_count()
    for cpu in range(n_cpus):
        affinity = [cpu]
        d = dict(affinity=affinity)
        p = mp.Process(target=run_child, kwargs=d)
        p.start()
        procs.append(p)
    for p in procs:
        p.join()
        print('joined')

def run_child(affinity):
    proc = psutil.Process()  # get self pid
    print('PID: {pid}'.format(pid=proc.pid))
    aff = proc.cpu_affinity()
    print('Affinity before: {aff}'.format(aff=aff))
    proc.cpu_affinity(affinity)
    aff = proc.cpu_affinity()
    print('Affinity after: {aff}'.format(aff=aff))
and supposed that that the scrips will use all cores and it actually does, but the speed drops down to ~60k h/s.
Can any one help to understand why it is? And how to improve the speed of this script?

This header alone in not enough to make the reste of the code work with more than one core !
 
Also
n_cpus = psutil.cpu_count() will probably give you the number of logical cores which is usually twice the number of physical cores (depends on what is your CPU).

you might try :
n_cpus = psutil.cpu_count() >> 1  
in principal, you'll get more speed per core

What cpu do you have?

Thanks, mate. It really did give a little more speed -> ~100k h/s. That what script shows. Maybe that is the speed per core? If yes then it's quite cool ))
Here is my benchmark addr #50:



PS I have CPU QuadCore Intel Core i7-6700HQ, 2500 MHz (25 x 100).

-------

Strange, but if I change to n_cpus = 3 it gives speed ~150k... Why?

-------

Is it possible to edit a number of threads per core?
zielar (OP)
Full Member
***
Offline Offline

Activity: 277
Merit: 106


View Profile
September 07, 2019, 11:50:15 PM
 #279

My new =>STABLE<= record on BitCrack :-)



NV Tesla  || The unstable setting showed me 1615, but it jumps from 1585 every reading. ||


If you want - you can send me a donation to my BTC wallet address 31hgbukdkehcuxcedchkdbsrygegyefbvd
almightyruler
Legendary
*
Offline Offline

Activity: 2268
Merit: 1092


View Profile
September 08, 2019, 01:46:52 AM
Last edit: September 08, 2019, 02:05:17 AM by almightyruler
 #280

I wrote a script to benchmark bit sizes from 16 to 50 bits:


bits     avgjump      avgtime
-----------------------------
[...]
48   |  60846064 |  828.8 sec
49   | 127443507 | 1706.6 sec
50   |   ...


The tests for 50 bits are still going, but so far the results for 5 runs are:

50   | 1071642261 | 16920.6 sec

49 = 127 443 507 jumps
50 = 1 071 642 261 jumps

Why does the work suddenly increase (by a factor of about 8 to 10, depending on time or jumps) when going from 49 to 50 bits? I notice the code warns "too big" if bits > 50
Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 [14] 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 »
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!