Show Posts
|
Pages: [1]
|
Hi Eter, It is possible to automatically printed output number of decimal; which are reduced. Yes, are you wanting to print all results to a .txt file? Hi, I wanted to automatically printed output number of decimal; which are reduced through bit range. As like: https://github.com/iceland2k14/quick/blob/main/PubSub.pyCould you please help me. write in details .... Hi, I have find range from script as below: Initial Pub: 0329fb788204d6b2b6797859572db2eb8c66c43756d4946bcad497ddec61b94d27 Priv: 0x1F3869ACC5B Key# 1 Pub: 0x02C9056EA5EBB46309024FF22C9668C2BEC887A0B3D48567CDB8D940F25B3C44D1 # -1072723486254 Priv: 0xF9C34D662D Key# 1 Pub: 0x033005E37EE6F877F86793334752F41E9243631C263414615A9B25DC98F35CF251 # -536361743127 Priv: 0x7CE1A6B316 Key# 1 Pub: 0x025196FA41B4A8D8A1D1C48BAAD791B5EF5CC8A489D510A2BF72B725E2423105F0 # -268180871563 Priv: 0x3E70D3598B As a result: divisor = 2**1 equivalent reduce is an 1 BIT range. So i wanted a output below example 0x02C9056EA5EBB46309024FF22C9668C2BEC887A0B3D48567CDB8D940F25B3C44D1 # -1072723486254 Please advice it is possible.
|
|
|
Hi Eter, It is possible to automatically printed output number of decimal; which are reduced. Yes, are you wanting to print all results to a .txt file? Hi, I wanted to automatically printed output number of decimal; which are reduced through bit range. As like: https://github.com/iceland2k14/quick/blob/main/PubSub.pyCould you please help me.
|
|
|
from fastecdsa import curve from fastecdsa.point import Point import bit
G = curve.secp256k1.G N = curve.secp256k1.q
def pub2point(pub_hex): x = int(pub_hex[2:66], 16) if len(pub_hex) < 70: y = bit.format.x_to_y(x, int(pub_hex[:2], 16) % 2) else: y = int(pub_hex[66:], 16) return Point(x, y, curve=curve.secp256k1)
# This function makes all the downscaled pubkeys obtained from subtracting # numbers between 0 and divisor, before dividing the pubkeys by divisor. def shiftdown(pubkey, divisor, file, convert=True): Q = pub2point(pubkey) if convert else pubkey # k = 1/divisor k = pow(divisor, N - 2, N) for i in range(divisor): P = Q - (i * G) P = k * P if (P.y % 2 == 0): prefix = "02" else: prefix = "03" hx = hex(P.x)[2:].zfill(64) hy = hex(P.y)[2:].zfill(64) file.write(prefix+ " " + hx+"\n") # Writes compressed key to file file.write("\n") # Writes compressed key to file
with open("input.txt", "r") as f, open("output.txt", "w") as outf: line = f.readline().strip() while line != '': outf.write("original: " +line + "\n") shiftdown(line, pow(2,1), outf) line = f.readline().strip() input: 02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 ..d13 is 4 and ...fe4 is 5 output: original: 02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 02 c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 02 c62c910e502cb615a27c58512b6cc2c94f5742f76cb3d12ec993400a3695d413
original: 022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 03 5699b93fc6e1bd29e09a328d657a607b4155b61a6b5fcbedd7c12df7c67df8f5 02 c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5
02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 is 2 Because i know 4 is even, i know it has to be the first pubkey. Because i know 5 is odd, I know it has to be the second key. The problem is, that in bigger numbers, you can not determine if it is odd or even. See,if I add the pubkey of 3 original: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 -> pubkey of 3 02 c62c910e502cb615a27c58512b6cc2c94f5742f76cb3d12ec993400a3695d413 -> not the halve 02 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 -> pubkey of 1
original: 02e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13 -> pubkey of 4 02 c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 -> odd pubkey of 5 02 c62c910e502cb615a27c58512b6cc2c94f5742f76cb3d12ec993400a3695d413 -> even pubkey of 3
original: 022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 -> pubkey of 5 03 5699b93fc6e1bd29e09a328d657a607b4155b61a6b5fcbedd7c12df7c67df8f5 -> not the halve 02 c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5-> pubkey of 2
You see... You can not determine from the halve if it is the correct one. Hi, It is possible to automatically printed output number of decimal; which are reduced.
|
|
|
Here is no magic, here is script to shiftdown pubkey: import random import math import hashlib import base58 def inverse(x, p): """ Calculate the modular inverse of x ( mod p ) """ inv1 = 1 inv2 = 0 n=1 while p != 1 and p!=0: quotient = x // p inv1, inv2 = inv2, inv1 - inv2 * quotient x, p = p, x % p n = n+1 return inv2
def dblpt(pt, p): """ Calculate pt+pt = 2*pt """ if pt is None: return None (x,y)= pt if y==0: return None slope= 3*pow(x,2,p)*pow(2*y,p-2,p) xsum= pow(slope,2,p)-2*x ysum= slope*(x-xsum)-y return (xsum%p, ysum%p)
def addpt(p1,p2, p): """ Calculate p1+p2 """ if p1 is None or p2 is None: return None (x1,y1)= p1 (x2,y2)= p2 if x1==x2: return dblpt(p1, p) # calculate (y1-y2)/(x1-x2) modulus p slope=(y1-y2)*pow(x1-x2,p-2,p) xsum= pow(slope,2,p)-(x1+x2) ysum= slope*(x1-xsum)-y1 return (xsum%p, ysum%p)
def ptmul(pt,a, p): """ Calculate pt*a """ scale= pt acc=None while a: if a&1: if acc is None: acc= scale else: acc= addpt(acc,scale, p) scale= dblpt(scale, p) a >>= 1 return acc
def ptdiv(pt,a,p,n): """ Calculate pt/a """ divpt=inverse(a, n)%n return ptmul(pt, divpt, p)
def isoncurve(pt,p): """ returns True when pt is on the secp256k1 curve """ (x,y)= pt return (y**2 - x**3 - 7)%p == 0
def getuncompressedpub(compressed_key): """ returns uncompressed public key """ y_parity = int(compressed_key[:2]) - 2 x = int(compressed_key[2:], 16) a = (pow(x, 3, p) + 7) % p y = pow(a, (p+1)//4, p) if y % 2 != y_parity: y = -y % p return (x,y)
def compresspub(uncompressed_key): """ returns uncompressed public key """ (x,y)=uncompressed_key y_parity = y&1 head='02' if y_parity ==1: head='03' compressed_key = head+'{:064x}'.format(x) return compressed_key
def hash160(hex_str): sha = hashlib.sha256() rip = hashlib.new('ripemd160') sha.update(hex_str) rip.update( sha.digest() ) return rip.hexdigest() # .hexdigest() is hex ASCII def getbtcaddr(pubkeyst): hex_str = bytearray.fromhex(pubkeyst) # Obtain key: key_hash = '00' + hash160(hex_str)
# Obtain signature:
sha = hashlib.sha256() sha.update( bytearray.fromhex(key_hash) ) checksum = sha.digest() sha = hashlib.sha256() sha.update(checksum) checksum = sha.hexdigest()[0:8]
return (base58.b58encode( bytes(bytearray.fromhex(key_hash + checksum)) )).decode('utf-8')
def checkpub(realpub, temppub, id): localpt = ptmul(temppub, 1024, p) localaddpt = ptmul(g, id, p) respub= addpt(localpt,localaddpt, p) print ("respub-> ", compresspub(respub)) #secp256k1 constants Gx=0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 Gy=0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8 n=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 p = 2**256 - 2**32 - 977 g= (Gx,Gy)
compressed_key='0234c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf' point=getuncompressedpub(compressed_key)
print(getbtcaddr("04%064x%064x"%point)) print(getbtcaddr(compressed_key)) divisor = 2**3 newpub=ptdiv(point,divisor,p,n)
(partGx,partGy)=ptdiv(g,divisor,p,n) print ("1 Fraction part-> (%x,%064x)" % (partGx,partGy))
with open('pub.txt', 'w') as f: f.write("04%064x%064x"%newpub) f.write('\n') print ("Compressed NewPUB (",0,")-> ", compresspub(newpub),"addr",getbtcaddr(compresspub(newpub))) i=1 (pointx,pointy)=(partGx,partGy) while i<divisor: (newpubtempx,newpubtempy) = addpt(newpub,(pointx,p-pointy), p) f.write("04%064x%064x"%(newpubtempx,newpubtempy)) f.write('\n') print ("Compressed NewPUB (",i,")-> ", compresspub((newpubtempx,newpubtempy)),"addr",getbtcaddr(compresspub((newpubtempx,newpubtempy)))) (pointx,pointy) = addpt((pointx,pointy),(partGx,partGy), p) i=i+1
In this example i use pubkey 0234c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf, privkey is 0x67 and upper range is 2^7 Divisor is 2^3, so new upper range is 2^7-2^3=2^4 In file pub.txt you will find all pubkeys and their number is equil to divisor. if you try to find all this keys in range 0x1:0xf you will see that only one pubkey will be lie in range And this pubkey is 03d01115d548e7561b15c38f004d734633687cf4419620095bc5b0f47070afe85a with privkey 0xC To produce real privkey need multiply privkey by divisor 0xC*0x8 = 0x60 After this need add to result founded public key number (7) Totaly privekey = 0x60 +0x7=0x67 Hi Eter, It is possible to automatically printed output number of decimal; which are reduced.
|
|
|
@albert0bsd, I am facing the same error issue while running this in ubantu 22.04 LTS
having gcc version gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
How to solve this please help.
thanks and Regards.
By same error, do you mean error message "collect2: error: ld returned 1 exit status"? I tried compiling this tool on newly installed Debian 11 and got similar error. My gcc version is gcc version 10.2.1 20210110 (Debian 10.2.1-6). gcc -O3 -c sha256/sha256.c -o sha256.o gcc -O3 -c base58/base58.c -o base58.o gcc -O3 -c rmd160/rmd160.c -o rmd160.o gcc -O3 -c gmpecc.c -o gmpecc.o gcc -O3 -c util.c -o util.o gcc -o keysubtracter keysubtracter.c gmpecc.o util.o sha256.o base58.o rmd160.o -lgmp /usr/bin/ld: gmpecc.o:(.bss+0x2020): multiple definition of `EC'; /tmp/ccwgKfYZ.o:(.bss+0x0): first defined here /usr/bin/ld: gmpecc.o:(.bss+0x0): multiple definition of `DoublingG'; /tmp/ccwgKfYZ.o:(.bss+0x40): first defined here /usr/bin/ld: gmpecc.o:(.bss+0x2000): multiple definition of `G'; /tmp/ccwgKfYZ.o:(.bss+0x20): first defined here collect2: error: ld returned 1 exit status make: *** [Makefile:7: default] Error 1
@albert0bsd, I am facing the same error issue while running this in Linux PC 4.4.0-19041-Microsoft #2311-Microsoft Tue Nov 08 17:09:00 PST 2022 x86_64 GNU/Linux ┌──(pc㉿PC)-[~/keysubtracter] └─$ sudo make gcc -O3 -c sha256/sha256.c -o sha256.o gcc -O3 -c base58/base58.c -o base58.o gcc -O3 -c rmd160/rmd160.c -o rmd160.o gcc -O3 -c gmpecc.c -o gmpecc.o gcc -O3 -c util.c -o util.o gcc -o keysubtracter keysubtracter.c gmpecc.o util.o sha256.o base58.o rmd160.o -lgmp /usr/bin/ld: gmpecc.o:(.bss+0x2020): multiple definition of `EC'; /tmp/ccbXGjoT.o:(.bss+0x0): first defined here /usr/bin/ld: gmpecc.o:(.bss+0x0): multiple definition of `DoublingG'; /tmp/ccbXGjoT.o:(.bss+0x40): first defined here /usr/bin/ld: gmpecc.o:(.bss+0x2000): multiple definition of `G'; /tmp/ccbXGjoT.o:(.bss+0x20): first defined here collect2: error: ld returned 1 exit status make: *** [Makefile:7: default] Error 1 ┌──(pc㉿PC)-[~/keysubtracter] └─$ uname -a Linux PC 4.4.0-19041-Microsoft #2311-Microsoft Tue Nov 08 17:09:00 PST 2022 x86_64 GNU/Linux ┌──(pc㉿PC)-[~/keysubtracter] └─$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-10' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-w47ffq/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-w47ffq/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Debian 12.2.0-10) @albert0bsd, having gcc version gcc How to solve this please help. thanks and Regards.
|
|
|
|