Bitcoin Forum
April 30, 2024, 03:03:09 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: list of simple mathematical operations in ECC secp256k1 (Python).  (Read 310 times)
mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
November 20, 2023, 06:30:10 PM
Last edit: December 07, 2023, 02:44:44 AM by mcdouglasx
Merited by Welsh (6), NotATether (6), vapourminer (4), digaran (1)
 #1

modules used:
Bitcoin
pip install bitcoin
---------------------------
secp256k1

download at https://github.com/iceland2k14/secp256k1

place files in the same folder as the script.




Decimal to Compressed Address

Code:
import secp256k1 as ice
            
target = 1

A0 = ice.scalar_multiplication(target)
A1 = A0.hex()
B0 = ice.pubkey_to_address(0,1, A0)
A2 = ice.to_cpub(A1)

print("Pk:",target)
print("cPub:",A2)
print("Addr:",B0)

addition of two points (publickeys)

Code:
import secp256k1 as ice

#A+B
A= "HERRE COMPRESSED PUBLIC KEY"
B= "HERRE COMPRESSED PUBLIC KEY"

Upub_A= ice.pub2upub(A)
Upub_B= ice.pub2upub(B)

A1= ice.point_addition(Upub_A, Upub_B).hex()

A2 = ice.to_cpub(A1)

print("R:",A2)

subtraction of two points (publickeys)
Code:
import secp256k1 as ice

#A-B
A= "HERE COMPRESSED PUBLIC KEY"
B= "HERE COMPRESSED PUBLIC KEY"

Upub_A= ice.pub2upub(A)
Upub_B= ice.pub2upub(B)

A1= ice.point_subtraction(Upub_A, Upub_B).hex()

A2 = ice.to_cpub(A1)

print("R:",A2)

multiply (publickey*decimal)

Code:
import bitcoin


target= "HERE COMPRESSED PUBLIC KEY"

N= 2

mult= bitcoin.multiply(target, N)

print(mult)


division (publickey/decimal)


Code:
import bitcoin


target= "HERE COMPRESSED PUBLIC KEY"

N= 2

Div= bitcoin.divide(target, N)

print(Div)

edit:

Division in Ecc works differently, I attach a division script with mod N that emulates the process in decimals, for your greater understanding.

Code:
import bitcoin

target= 1361129467683753853853498429727072845823

Div=2

N=115792089237316195423570985008687907852837564279074904382605163141518161494337

a=bitcoin.inv(Div,N)

b= target*a % N

print("pk:",b)


Upub to Cpub

Code:
import secp256k1 as ice
           
target = “UNCOMPRESSED PUB HERE”

A2 = ice.to_cpub(target)
print("Cpub:", A2)

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
1714489389
Hero Member
*
Offline Offline

Posts: 1714489389

View Profile Personal Message (Offline)

Ignore
1714489389
Reply with quote  #2

1714489389
Report to moderator
1714489389
Hero Member
*
Offline Offline

Posts: 1714489389

View Profile Personal Message (Offline)

Ignore
1714489389
Reply with quote  #2

1714489389
Report to moderator
The network tries to produce one block per 10 minutes. It does this by automatically adjusting how difficult it is to produce blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714489389
Hero Member
*
Offline Offline

Posts: 1714489389

View Profile Personal Message (Offline)

Ignore
1714489389
Reply with quote  #2

1714489389
Report to moderator
1714489389
Hero Member
*
Offline Offline

Posts: 1714489389

View Profile Personal Message (Offline)

Ignore
1714489389
Reply with quote  #2

1714489389
Report to moderator
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6715


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 21, 2023, 08:34:44 AM
Merited by vapourminer (1), mcdouglasx (1)
 #2


division (publickey/decimal)


Code:
import bitcoin


target= "HERE COMPRESSED PUBLIC KEY"

N= 2

Div= bitcoin.divide(target, N)

print(Div)

Division cannot exactly undo multiplication without taking remainders into account, because elliptic curve multiplication is like a "many-to-one" function. When you divide like this you get the 0th quotient, but there are always 'i'+1 remainders that can be calculated for a division by 'i' and you get each one by subtracting i*G from the public key before dividing (i.e. inverse multiplying).

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
ElDalmatino
Jr. Member
*
Offline Offline

Activity: 53
Merit: 11


View Profile
November 22, 2023, 12:50:31 PM
 #3

Sorry, but i try to figure out how to use the private key to public key (compressed), function of iceland2k14 secp256k1, maybe i have a mind block or i can't remember.
albert0bsd
Hero Member
*****
Offline Offline

Activity: 850
Merit: 660



View Profile WWW
November 22, 2023, 01:00:26 PM
 #4

OP when i saw the title "list of simple mathematical operations in ECC secp256k1 (Python)." I think that those funtions will be implemented directly in python only... I don't see why you get merit just by showing someone else code here.

digaran
Copper Member
Hero Member
*****
Offline Offline

Activity: 1330
Merit: 899

🖤😏


View Profile
November 22, 2023, 01:16:28 PM
Merited by mcdouglasx (1)
 #5


What do you mean implementing directly? Of course it's not someone else's code, these are mathematical functions and there is no copyrights or anything.

Btw, you already have the fastest tools here, no need to overreact. 😉

🖤😏
mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
November 22, 2023, 01:28:07 PM
 #6

OP when i saw the title "list of simple mathematical operations in ECC secp256k1 (Python)." I think that those funtions will be implemented directly in python only... I don't see why you get merit just by showing someone else code here.

If I had wanted to put only python code (without modules) it would no longer be "simple", but would be expressed in the title "pure python", my idea is to make it easy for those looking for simple and quick solutions, excuse me if I receive merits for that, but I don't choose who gives them to me.

Simple: "easily understood or done; presenting no difficulty".

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
November 22, 2023, 01:31:56 PM
 #7

Sorry, but i try to figure out how to use the private key to public key (compressed), function of iceland2k14 secp256k1, maybe i have a mind block or i can't remember.

place files in the same folder as the script.


Code:
Code:
import secp256k1 as ice
           
target = 1

A0 = ice.scalar_multiplication(target)
A1 = A0.hex()
A2 = ice.to_cpub(A1)

print("Pk:",target)
print("cPub:",A2)

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
ymgve2
Full Member
***
Offline Offline

Activity: 161
Merit: 230


View Profile
November 22, 2023, 04:01:11 PM
Merited by albert0bsd (4)
 #8

OP when i saw the title "list of simple mathematical operations in ECC secp256k1 (Python)." I think that those funtions will be implemented directly in python only... I don't see why you get merit just by showing someone else code here.

If you want some of these functions in pure Python, I've got some older code that does it:

https://gist.github.com/ymgve/efc307e173ed9ea8cb2cac3c7462ed7b

(The main code is for claiming some garbage fork coin, but the ECC primitives work the same)
albert0bsd
Hero Member
*****
Offline Offline

Activity: 850
Merit: 660



View Profile WWW
November 22, 2023, 04:17:21 PM
 #9

Simple: "easily understood or done; presenting no difficulty".

It is going to be the same, you only need to create a python file class that use the same functions names and parameters.. that is more educative in that way

The main code that use those functions its going to be simple, the complex file only need to be imported

If you want some of these functions in pure Python, I've got some older code that does it:

I don't want them I already have it in C  and C++, but is nice see those in python

mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
November 22, 2023, 05:01:47 PM
 #10

It is going to be the same, you only need to create a python file class that use the same functions names and parameters.. that is more educative in that way

The main code that use those functions its going to be simple, the complex file only need to be imported


What you ask for is absurd, you criticize from selfishness (or is what it seems):
It is the equivalent of asking you instead of using for example:
  #include secp256k1.h
Create your own code for secp256k1.
Your argument has no basis, especially when it is a post dedicated to simplicity, ease and minimalism.

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
ElDalmatino
Jr. Member
*
Offline Offline

Activity: 53
Merit: 11


View Profile
November 22, 2023, 05:35:05 PM
 #11

Sorry, but i try to figure out how to use the private key to public key (compressed), function of iceland2k14 secp256k1, maybe i have a mind block or i can't remember.

place files in the same folder as the script.


Code:
Code:
import secp256k1 as ice
           
target = 1

A0 = ice.scalar_multiplication(target)
A1 = A0.hex()
A2 = ice.to_cpub(A1)

print("Pk:",target)
print("cPub:",A2)

Thank you  exactly what i search for.

I think this is a good thread .. why because its on point .. need some fast short code, here it is, sometimes the script or codecrumbs, dissapear in endless useless discussions.
albert0bsd
Hero Member
*****
Offline Offline

Activity: 850
Merit: 660



View Profile WWW
November 22, 2023, 05:46:05 PM
 #12

What you ask for is absurd

Not is not absurd the user ymgve2 already post the python code.

It is the equivalent of asking you instead of using for example:
  #include secp256k1.h
Create your own code for secp256k1.

I create it in C if you see the C code of the first version of keyhunt i did it from zero... check it here

But  its ok, if you don't know how to do it, its OK i have no problem with it.


mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
November 22, 2023, 06:28:50 PM
 #13

What you ask for is absurd

Not is not absurd the user ymgve2 already post the python code.

It is the equivalent of asking you instead of using for example:
  #include secp256k1.h
Create your own code for secp256k1.

I create it in C if you see the C code of the first version of keyhunt i did it from zero... check it here

But  its ok, if you don't know how to do it, its OK i have no problem with it.



It's not that I don't know (the truth is it's not a challenge), I don't know why you can't understand that the focus of the code here is to be easy to use, and friendly to the eye, just like a+b=c.

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
digaran
Copper Member
Hero Member
*****
Offline Offline

Activity: 1330
Merit: 899

🖤😏


View Profile
November 22, 2023, 08:33:29 PM
 #14

You should also add double point torsion with the possibility to add and subtract the results, you know the one that subtracts 1 divides by 2, it's a groundbreaking simple algorithm. Don't know if anyone has tried to manipulate the keys and try different values or not.
Btw, it's a free for all to use, no copyrights.😉
And technically ECC is considered advanced mathematics, there is no easy and simple to the eyes. But I get what you mean.

🖤😏
ecdsa123
Full Member
***
Offline Offline

Activity: 211
Merit: 105

Dr WHO on disney+


View Profile
November 23, 2023, 10:05:55 AM
Merited by vjudeu (1)
 #15

you can add additional operations like on pubkeys but this time as operate on signatures.


example:

we have r,s,z and pubkey:


you can implement :

1. Divide transaction by integer to get valid new transaction for this pubkey
2. Add nonce to this transaction
3. sub the nonce from this transaction

and so on..

Donate: bc1q0sezldfgm7rf2r78p5scasrrcfkpzxnrfcvdc6

Subscribe : http://www.youtube.com/@Ecdsa_Solutions
digaran
Copper Member
Hero Member
*****
Offline Offline

Activity: 1330
Merit: 899

🖤😏


View Profile
November 23, 2023, 11:23:25 AM
 #16

you can add additional operations like on pubkeys but this time as operate on signatures.


example:

we have r,s,z and pubkey:


you can implement :

1. Divide transaction by integer to get valid new transaction for this pubkey
2. Add nonce to this transaction
3. sub the nonce from this transaction

and so on..
Cool suggestion but that is not what we are after in this community, however for the sake of scientific research, do you have that script or no? If you have gimme it.

🖤😏
ElDalmatino
Jr. Member
*
Offline Offline

Activity: 53
Merit: 11


View Profile
December 06, 2023, 11:32:58 PM
 #17

Hi your list of list of simple mathematical operations in ECC secp256k1 is a big help for me, can i ask you if there is also a code to get the compressed version of a uncompressed public key.
mcdouglasx (OP)
Member
**
Offline Offline

Activity: 239
Merit: 53

New ideas will be criticized and then admired.


View Profile WWW
December 07, 2023, 12:15:20 AM
Merited by ElDalmatino (1)
 #18

Hi your list of list of simple mathematical operations in ECC secp256k1 is a big help for me, can i ask you if there is also a code to get the compressed version of a uncompressed public key.

Code:
import secp256k1 as ice
           
target = “UNCOMPRESSED PUB HERE”

A2 = ice.to_cpub(target)
print(A2)

I'm not dead, long story... BTC bc1qxs47ttydl8tmdv8vtygp7dy76lvayz3r6rdahu
Pages: [1]
  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!