Author

Topic: list of simple mathematical operations in ECC secp256k1 (Python). (Read 367 times)

member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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)
jr. member
Activity: 53
Merit: 11
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.
copper member
Activity: 1330
Merit: 899
🖤😏
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.
copper member
Activity: 1330
Merit: 899
🖤😏
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.
member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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.
hero member
Activity: 862
Merit: 662
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.

jr. member
Activity: 53
Merit: 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.
member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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.
hero member
Activity: 862
Merit: 662
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
full member
Activity: 161
Merit: 230
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)
member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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)
member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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".
copper member
Activity: 1330
Merit: 899
🖤😏

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. 😉
hero member
Activity: 862
Merit: 662
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.
jr. member
Activity: 53
Merit: 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.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org

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).
member
Activity: 239
Merit: 53
New ideas will be criticized and then admired.
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)
Jump to: