Author

Topic: Public Key (Read 987 times)

hero member
Activity: 501
Merit: 503
December 15, 2014, 09:16:50 PM
#10
I am working on a set of tools and guides to create a sort of guideline.
Presumably your guideline will recommend users _never_ use uncompressed public keys?

The tools and guides will be open but i will try to use red extra large letters detailing why they should not. I became interested when i saw this part of the bitcoin code:-

Quote
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3 8c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
       

I hope i'm right that it actually is an uncompressed pub key. The idea is in the same direction as a question on this board about dealing with blockchain bloat.
staff
Activity: 4284
Merit: 8808
December 15, 2014, 06:21:40 PM
#9
I am working on a set of tools and guides to create a sort of guideline.
Presumably your guideline will recommend users _never_ use uncompressed public keys?
sr. member
Activity: 392
Merit: 268
Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ
December 15, 2014, 06:18:25 PM
#8
Go here

http[Suspicious link removed]cute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.


Why not just use a standard python interpreter? Why use a webservice?
Not everyone knows python.
Doesn't mean copy-pasting into a python prompt is necessarily out-of-reach. I did a double-take at first since I thought it took private keys. Still sketchy when a decent solution exists.
hero member
Activity: 765
Merit: 503
December 15, 2014, 06:13:57 PM
#7
Go here

http[Suspicious link removed]cute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.


Why not just use a standard python interpreter? Why use a webservice?
Not everyone knows python.
sr. member
Activity: 392
Merit: 268
Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ
December 15, 2014, 12:11:42 PM
#6
Go here

http[Suspicious link removed]cute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.


Why not just use a standard python interpreter? Why use a webservice?
hero member
Activity: 501
Merit: 503
December 15, 2014, 11:57:39 AM
#5
Go here

http://www.tutorialspoint.com/execute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.

Code:
###############
compressed_key = 'xxxxxxxxxxxx'
###############

def pow_mod(x, y, z):
    "Calculate (x ** y) % z efficiently."
    number = 1
    while y:
        if y & 1:
            number = number * x % z
        y >>= 1
        x = x * x % z
    return number

p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
y_parity = int(compressed_key[:2]) - 2
x = int(compressed_key[2:], 16)
a = (pow_mod(x, 3, p) + 7) % p
y = pow_mod(a, (p+1)//4, p)
if y % 2 != y_parity:
    y = -y % p
uncompressed_key = '04{:x}{:x}'.format(x, y)
print()
print()
print(uncompressed_key)
print()
print()


Worked like a charm, thank you
hero member
Activity: 501
Merit: 503
December 15, 2014, 11:49:20 AM
#4
Go here

http://www.tutorialspoint.com/execute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.

Code:
###############
compressed_key = 'xxxxxxxxxxxx'
###############

def pow_mod(x, y, z):
    "Calculate (x ** y) % z efficiently."
    number = 1
    while y:
        if y & 1:
            number = number * x % z
        y >>= 1
        x = x * x % z
    return number

p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
y_parity = int(compressed_key[:2]) - 2
x = int(compressed_key[2:], 16)
a = (pow_mod(x, 3, p) + 7) % p
y = pow_mod(a, (p+1)//4, p)
if y % 2 != y_parity:
    y = -y % p
uncompressed_key = '04{:x}{:x}'.format(x, y)
print()
print()
print(uncompressed_key)
print()
print()


thanks, gonna try it out now. 

It seems the client only gives out compressed public keys, how can i get the uncompressed one?

Why exactly would you want to get uncompressed ones?


I am working on a set of tools and guides to create a sort of guideline.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
December 15, 2014, 10:19:14 AM
#3
It seems the client only gives out compressed public keys, how can i get the uncompressed one?

Why exactly would you want to get uncompressed ones?
sr. member
Activity: 475
Merit: 252
December 15, 2014, 10:14:34 AM
#2
Go here

http://www.tutorialspoint.com/execute_python3_online.php

Copy this into the middle window that has the code for hello world, delete all code and paste this code
replace the xxxxxxxxxxxx with your compressed pubkey.

Then click execute and the uncompressed pubkey will show up in the console.

Code:
###############
compressed_key = 'xxxxxxxxxxxx'
###############

def pow_mod(x, y, z):
    "Calculate (x ** y) % z efficiently."
    number = 1
    while y:
        if y & 1:
            number = number * x % z
        y >>= 1
        x = x * x % z
    return number

p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
y_parity = int(compressed_key[:2]) - 2
x = int(compressed_key[2:], 16)
a = (pow_mod(x, 3, p) + 7) % p
y = pow_mod(a, (p+1)//4, p)
if y % 2 != y_parity:
    y = -y % p
uncompressed_key = '04{:x}{:x}'.format(x, y)
print()
print()
print(uncompressed_key)
print()
print()
hero member
Activity: 501
Merit: 503
December 15, 2014, 09:57:03 AM
#1
It seems the client only gives out compressed public keys, how can i get the uncompressed one?
Jump to: