<p>This has been answered already in:<br/>
(<a href="https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key">How do you get a Bitcoin Public Key from a Private Key</a>)</p>
<p>Look at the answer of <em>@user1658887</em> for example.</p>
<p>EDIT: Given the fact that you're asking for the public key output in uncompressed <em>hex</em> format explicitly, here are some wrapping code lines around the the stuff that <em>user1658887</em> posted in the answer referenced above:<br/></p>
<pre><code>import binascii
import struct
import sys

# code taken from user1658887's answer at: https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key

def sk_to_pk(sk):
    &quot;&quot;&quot;
    Derive the public key of a secret key on the secp256k1 curve.

    Args:
        sk: An integer representing the secret key (also known as secret
      exponent).

    Returns:
        A coordinate (x, y) on the curve repesenting the public key
      for the given secret key.

    Raises:
        ValueError: The secret key is not in the valid range [1,N-1].
    &quot;&quot;&quot;
    # base point (generator)
    G = (0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
     0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8)

    # field prime
    P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F

    # order
    N = (1 &lt;&lt; 256) - 0x14551231950B75FC4402DA1732FC9BEBF

    # check if the key is valid
    if not(0 &lt; sk &lt; N):
        msg = &quot;{} is not a valid key (not in range [1, {}])&quot;
        raise ValueError(msg.format(hex(sk), hex(N-1)))

    # addition operation on the elliptic curve
    # see: https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Point_addition
    # note that the coordinates need to be given modulo P and that division is
    # done by computing the multiplicative inverse, which can be done with
    # x^-1 = x^(P-2) mod P using fermat's little theorem (the pow function of
    # python can do this efficiently even for very large P)
    def add(p, q):
        px, py = p
        qx, qy = q
        if p == q:
            lam = (3 * px * px) * pow(2 * py, P - 2, P)
        else:
            lam = (qy - py) * pow(qx - px, P - 2, P)
        rx = lam**2 - px - qx
        ry = lam * (px - rx) - py
        return rx % P, ry % P

    # compute G * sk with repeated addition
    # by using the binary representation of sk this can be done in 256
    # iterations (double-and-add)
    ret = None
    for i in xrange(256):
        if sk &amp; (1 &lt;&lt; i):
            if ret is None:
                ret = G
        else:
            ret = add(ret, G)
        G = add(G, G)

    return ret

if len(sys.argv) &gt;= 2:
    sk = long(sys.argv[1], 16)
else:
    raise ValueError('Please provide the private key in hex format as a 1st parameter')

pk = sk_to_pk(sk)
pkx, pky = pk
ybyte=0x02 if pky % 2 == 0 else 0x03       # can be used when a compressed pubkey is desired
hexpk = &quot;%s%s%s&quot; % (&quot;04&quot;,hex(pkx),hex(pky))    # 04 indicates that an uncompressed pubkey is desired
print (hexpk.replace(&quot;0x&quot;,&quot;&quot;,2).replace(&quot;L&quot;,&quot;&quot;,2));
</code></pre>
<p>Which gives you your desired result: <br/></p>
<pre><code>~/$ python priv2pub.py B54FD9915A8B6870647705E91D4D953BA34B2B53F4681FDEFD50ECC13507BEFC
0413775e7a37881a284dac76217f12d610fc8fc67f82e73cd56a4d98f149cbc8e3ef8b012e9670ab1ba1cf40125921a59cc736cc7cfe8c6a6bacdd1327440343cf
</code></pre>

CC BY-SA 4.0
2020-06-29T14:25:46.557Z
Disculpame pero no esta respondido de la forma que deseaba..Yo estoy suministrando la Clave Privada y desde alli queria generar la llave publica descomprilda de 130 caracteres.. Mientra que la respuesta que esta publicada.... el script genera de forma aleatoria la clave privada y la llave publica..... eso no es lo que quiero
Alfredo Eduardo
CC BY-SA 4.0
2020-06-29T14:49:57.243Z
es exactamente lo que el script hace: La forma de uso es: `python priv2pub.py <clave privada>` y el resultado es la llave publica (130 caracteres). Mira el 'EDIT' de mi respuesta.
citizenfu
CC BY-SA 4.0
2020-06-29T12:29:35.913Z
2020-10-06T09:45:17.683Z
2020-10-06T09:45:17.683Z
citizenfu
<p>I want to know how I can build a Python script that can Calculate Public Key ECDSA from a Private Key (HEX) and the result is similar to the imagen</p>
<p><a href="https://i.sstatic.net/jbV9D.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jbV9D.jpg" alt="enter image description here" /></a></p>

<ecdsa>
PUBLIC ECDSA KEY
Alfredo Eduardo
# PUBLIC ECDSA KEY

(Asked by: username_0 on 2020-06-28)

I want to know how I can build a Python script that can Calculate Public Key ECDSA from a Private Key (HEX) and the result is similar to the imagen

[![enter image description here](https://i.sstatic.net/jbV9D.jpg)](https://i.sstatic.net/jbV9D.jpg)

**Tags:** ecdsa


---

## 1 answers

### Answer by username_1 on 2020-06-29. Score: 2

This has been answered already in:
(How do you get a Bitcoin Public Key from a Private Key)
Look at the answer of @user1658887 for example.
EDIT: Given the fact that you're asking for the public key output in uncompressed hex format explicitly, here are some wrapping code lines around the the stuff that user1658887 posted in the answer referenced above:
import binascii
import struct
import sys

# code taken from user1658887's answer at: https://bitcoin.stackexchange.com/questions/25024/how-do-you-get-a-bitcoin-public-key-from-a-private-key

def sk_to_pk(sk):
    """
    Derive the public key of a secret key on the secp256k1 curve.

    Args:
        sk: An integer representing the secret key (also known as secret
      exponent).

    Returns:
        A coordinate (x, y) on the curve repesenting the public key
      for the given secret key.

    Raises:
        ValueError: The secret key is not in the valid range [1,N-1].
    """
    # base point (generator)
    G = (0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
     0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8)

    # field prime
    P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F

    # order
    N = (1 << 256) - 0x14551231950B75FC4402DA1732FC9BEBF

    # check if the key is valid
    if not(0 < sk < N):
        msg = "{} is not a valid key (not in range [1, {}])"
        raise ValueError(msg.format(hex(sk), hex(N-1)))

    # addition operation on the elliptic curve
    # see: https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Point_addition
    # note that the coordinates need to be given modulo P and that division is
    # done by computing the multiplicative inverse, which can be done with
    # x^-1 = x^(P-2) mod P using fermat's little theorem (the pow function of
    # python can do this efficiently even for very large P)
    def add(p, q):
        px, py = p
        qx, qy = q
        if p == q:
            lam = (3 * px * px) * pow(2 * py, P - 2, P)
        else:
            lam = (qy - py) * pow(qx - px, P - 2, P)
        rx = lam**2 - px - qx
        ry = lam * (px - rx) - py
        return rx % P, ry % P

    # compute G * sk with repeated addition
    # by using the binary representation of sk this can be done in 256
    # iterations (double-and-add)
    ret = None
    for i in xrange(256):
        if sk & (1 << i):
            if ret is None:
                ret = G
        else:
            ret = add(ret, G)
        G = add(G, G)

    return ret

if len(sys.argv) >= 2:
    sk = long(sys.argv[1], 16)
else:
    raise ValueError('Please provide the private key in hex format as a 1st parameter')

pk = sk_to_pk(sk)
pkx, pky = pk
ybyte=0x02 if pky % 2 == 0 else 0x03       # can be used when a compressed pubkey is desired
hexpk = "%s%s%s" % ("04",hex(pkx),hex(pky))    # 04 indicates that an uncompressed pubkey is desired
print (hexpk.replace("0x","",2).replace("L","",2));

Which gives you your desired result: 
~/$ python priv2pub.py B54FD9915A8B6870647705E91D4D953BA34B2B53F4681FDEFD50ECC13507BEFC
0413775e7a37881a284dac76217f12d610fc8fc67f82e73cd56a4d98f149cbc8e3ef8b012e9670ab1ba1cf40125921a59cc736cc7cfe8c6a6bacdd1327440343cf

> **Comments:**
> **username_0**: Disculpame pero no esta respondido de la forma que deseaba..Yo estoy suministrando la Clave Privada y desde alli queria generar la llave publica descomprilda de 130 caracteres.. Mientra que la respuesta que esta publicada.... el script genera de forma aleatoria la clave privada y la llave publica..... eso no es lo que quiero  
> **username_1**: es exactamente lo que el script hace: La forma de uso es: `python priv2pub.py <clave privada>` y el resultado es la llave publica (130 caracteres). Mira el 'EDIT' de mi respuesta.  

---

