Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: hack_ on December 15, 2014, 02:57:03 PM



Title: Public Key
Post by: hack_ on December 15, 2014, 02:57:03 PM
It seems the client only gives out compressed public keys, how can i get the uncompressed one?


Title: Re: Public Key
Post by: dabura667 on December 15, 2014, 03:14:34 PM
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()


Title: Re: Public Key
Post by: CIYAM on December 15, 2014, 03:19:14 PM
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?


Title: Re: Public Key
Post by: hack_ on December 15, 2014, 04:49:20 PM
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.


Title: Re: Public Key
Post by: hack_ on December 15, 2014, 04:57:39 PM
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


Title: Re: Public Key
Post by: hexafraction on December 15, 2014, 05:11:42 PM
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?


Title: Re: Public Key
Post by: doof on December 15, 2014, 11:13:57 PM
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.


Title: Re: Public Key
Post by: hexafraction on December 15, 2014, 11:18:25 PM
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.


Title: Re: Public Key
Post by: gmaxwell on December 15, 2014, 11:21:40 PM
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?


Title: Re: Public Key
Post by: hack_ on December 16, 2014, 02:16:50 AM
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.