<p>Your python scripts generate uncompressed public keys, and they seem to calculate correctly.<br/>
When I use my own scripts, the results are:<br/></p>
<pre><code>Private key: ---------------------------------------
5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d
Private WIF: ---------------------------------------
Kz66jawQ5eb7pQYJx3tTNmFQBS46x1rg92To2js3bY1SKrPxVWvL
Public key: ----------------------------------------
04cbeefab6ecfa84f5f120503de4574952f2d1fa5b11b8f6c80a13df02e6512090e6fede6dde3e65256c484162e3839cf599c3d08a236432e8e307784b741ffca5
pubkeyhash: ----------------------------------------
50cdf408e049ddab4bd8ebda8a6500e93831a633
BTC Address: ---------------------------------------
18NFnELB9YpRiEbLMmRLKymYpvxC9yzkC2
</code></pre>
<p>No difference to your results.<br/></p>
<p>But there seems to be a bug in walletgenerator.net's calculation:<br/>
They claim that the uncompressed address was the same as the compressed address, which cannot be correct. Which tab did you use on their site, was it <em>Wallet Details</em>?<br/>
As a <em>compressed</em> bitcoin address, I get <code>1KJKsAzDeH1127x6w8e2xZyzRdvFkiLhme</code> when I use my own scripts, and my Electrum client confirms that result (when I use the private key import feature).<br/></p>
<p>All that does not match the results of <code>walletgenerator.net</code>, so my conclusion is that their site is buggy.<br/></p>

CC BY-SA 4.0
2020-07-13T13:29:02.413Z
Thank you @citizenfu, yes, I tried to check the values on _Wallet Details_. It's a good thing hear from you that it is not my script what's wrong
Stack
CC BY-SA 4.0
2020-07-13T11:37:51.623Z
2020-07-13T11:37:51.623Z
citizenfu
<p>I had created a script that creates a bitcoin private key, public key and address, for checking if all works fine I create one and check the private key on <a href="https://walletgenerator.net/" rel="nofollow noreferrer">https://walletgenerator.net/</a>, and it outputs a different address, every time I do that my script create a different addres that what walletgenerator returns.</p>
<p>Python script:</p>
<pre><code>import secrets
</code></pre>
<p>import hashlib
import ecdsa
import codecs
import base64</p>
<p>class Address():
def <strong>init</strong>(self):
self.private_key = self.create_private_key()<br />
self.public_key = self.private_key_to_public(self.private_key)
self.address = self.public_key_to_address(self.public_key)</p>
<pre><code>@staticmethod
def create_private_key():
    bits = secrets.randbits(256)
    bits_hex = hex(bits)
    private_key = bits_hex[2:]
    return private_key


@staticmethod
def private_key_to_public(private_key):
    verify_key = ecdsa.SigningKey.from_string(codecs.decode(private_key, &quot;hex&quot;), curve=ecdsa.SECP256k1).verifying_key
    key_hex = codecs.encode(verify_key.to_string(), &quot;hex&quot;)
    bitcoin_type = b'04'
    public_key = bitcoin_type + key_hex
    return public_key
    

@staticmethod
def public_key_to_address(public_key):
    public_key_bytes = codecs.decode(public_key, &quot;hex&quot;)
    
    sha256_bpk = hashlib.sha256(public_key_bytes)
    sha256_bpk_digest = sha256_bpk.digest()
    
    ripemd160_bpk = hashlib.new(&quot;ripemd160&quot;)
    ripemd160_bpk.update(sha256_bpk_digest)
    ripemd160_bpk_digest = ripemd160_bpk.digest()
    ripemd160_bpk_hex = codecs.encode(ripemd160_bpk_digest, &quot;hex&quot;)
    network_byte = b'00'
    network_bitcoin_public_key = network_byte + ripemd160_bpk_hex

    network_bitcoin_public_key_bytes = codecs.decode(network_bitcoin_public_key, 'hex')
    # Double SHA256 to get checksum
    sha256_nbpk = hashlib.sha256(network_bitcoin_public_key_bytes)
    sha256_nbpk_digest = sha256_nbpk.digest()
    sha256_2_nbpk = hashlib.sha256(sha256_nbpk_digest)
    sha256_2_nbpk_digest = sha256_2_nbpk.digest()
    sha256_2_hex = codecs.encode(sha256_2_nbpk_digest, &quot;hex&quot;)
    checksum = sha256_2_hex[:8]

    address_hex = (network_bitcoin_public_key + checksum).decode('utf-8')
    return Address.base58(address_hex)

@staticmethod
def base58(address_hex):
    alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
    b58_string = ''
    # Get the number of leading zeros
    leading_zeros = len(address_hex) - len(address_hex.lstrip('0'))
    # Convert hex to decimal
    address_int = int(address_hex, 16)
    # Append digits to the start of string
    while address_int &gt; 0:
        digit = address_int % 58
        digit_char = alphabet[digit]
        b58_string = digit_char + b58_string
        address_int //= 58
    # Add ‘1’ for each 2 leading zeros
    ones = leading_zeros // 2
    for _ in range(ones):
        b58_string = '1' + b58_string
    return b58_string
</code></pre>
<p>Doing</p>
<pre><code>foo = Address()
print(foo.private_key, foo.public_key, foo.address)
</code></pre>
<p>returns</p>
<pre><code># 5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d 
# b'04cbeefab6ecfa84f5f120503de4574952f2d1fa5b11b8f6c80a13df02e6512090e6fede6dde3e65256c484162e38 
# 39cf599c3d08a236432e8e307784b741ffca5' 18NFnELB9YpRiEbLMmRLKymYpvxC9yzkC2
</code></pre>
<p>And then, if I check the private key <code>5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d</code> on <a href="https://walletgenerator.net/" rel="nofollow noreferrer">https://walletgenerator.net/</a>, it returns:</p>
<pre><code>Public address: 1LBLgjq3ntVdb8MqB41rHReWnrKgT41Lwv
Public address compressed: 1LBLgjq3ntVdb8MqB41rHReWnrKgT41Lwv
</code></pre>

CC BY-SA 4.0
2020-07-13T20:38:26.197Z
walletgenerator.net is probably a phishing site
Tony Sanak
<wallet><address><address-generation><python>
Address generator error with python
Stack
# Address generator error with python

(Asked by: username_0 on 2020-07-13)

I had created a script that creates a bitcoin private key, public key and address, for checking if all works fine I create one and check the private key on <https://walletgenerator.net/>, and it outputs a different address, every time I do that my script create a different addres that what walletgenerator returns.

Python script:

```
import secrets

```

import hashlib
import ecdsa
import codecs
import base64

class Address():
def **init**(self):
self.private\_key = self.create\_private\_key()  
self.public\_key = self.private\_key\_to\_public(self.private\_key)
self.address = self.public\_key\_to\_address(self.public\_key)

```
@staticmethod
def create_private_key():
    bits = secrets.randbits(256)
    bits_hex = hex(bits)
    private_key = bits_hex[2:]
    return private_key

@staticmethod
def private_key_to_public(private_key):
    verify_key = ecdsa.SigningKey.from_string(codecs.decode(private_key, "hex"), curve=ecdsa.SECP256k1).verifying_key
    key_hex = codecs.encode(verify_key.to_string(), "hex")
    bitcoin_type = b'04'
    public_key = bitcoin_type + key_hex
    return public_key
    

@staticmethod
def public_key_to_address(public_key):
    public_key_bytes = codecs.decode(public_key, "hex")
    
    sha256_bpk = hashlib.sha256(public_key_bytes)
    sha256_bpk_digest = sha256_bpk.digest()
    
    ripemd160_bpk = hashlib.new("ripemd160")
    ripemd160_bpk.update(sha256_bpk_digest)
    ripemd160_bpk_digest = ripemd160_bpk.digest()
    ripemd160_bpk_hex = codecs.encode(ripemd160_bpk_digest, "hex")
    network_byte = b'00'
    network_bitcoin_public_key = network_byte + ripemd160_bpk_hex

    network_bitcoin_public_key_bytes = codecs.decode(network_bitcoin_public_key, 'hex')
    # Double SHA256 to get checksum
    sha256_nbpk = hashlib.sha256(network_bitcoin_public_key_bytes)
    sha256_nbpk_digest = sha256_nbpk.digest()
    sha256_2_nbpk = hashlib.sha256(sha256_nbpk_digest)
    sha256_2_nbpk_digest = sha256_2_nbpk.digest()
    sha256_2_hex = codecs.encode(sha256_2_nbpk_digest, "hex")
    checksum = sha256_2_hex[:8]

    address_hex = (network_bitcoin_public_key + checksum).decode('utf-8')
    return Address.base58(address_hex)

@staticmethod
def base58(address_hex):
    alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
    b58_string = ''
    # Get the number of leading zeros
    leading_zeros = len(address_hex) - len(address_hex.lstrip('0'))
    # Convert hex to decimal
    address_int = int(address_hex, 16)
    # Append digits to the start of string
    while address_int > 0:
        digit = address_int % 58
        digit_char = alphabet[digit]
        b58_string = digit_char + b58_string
        address_int //= 58
    # Add ‘1’ for each 2 leading zeros
    ones = leading_zeros // 2
    for _ in range(ones):
        b58_string = '1' + b58_string
    return b58_string

```

Doing

```
foo = Address()
print(foo.private_key, foo.public_key, foo.address)

```

returns

```
# 5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d 
# b'04cbeefab6ecfa84f5f120503de4574952f2d1fa5b11b8f6c80a13df02e6512090e6fede6dde3e65256c484162e38 
# 39cf599c3d08a236432e8e307784b741ffca5' 18NFnELB9YpRiEbLMmRLKymYpvxC9yzkC2

```

And then, if I check the private key `5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d` on <https://walletgenerator.net/>, it returns:

```
Public address: 1LBLgjq3ntVdb8MqB41rHReWnrKgT41Lwv
Public address compressed: 1LBLgjq3ntVdb8MqB41rHReWnrKgT41Lwv

```

**Tags:** wallet, address, address-generation, python

> **Comments:**
> **username_1**: walletgenerator.net is probably a phishing site  

---

## 1 answers

### Answer by username_2 on 2020-07-13. Score: 0 | Accepted answer

Your python scripts generate uncompressed public keys, and they seem to calculate correctly.  
When I use my own scripts, the results are:

```
Private key: ---------------------------------------
5598c164e8bcec667589267cdaf0f14a6b9399ae0b2a6b10972602a6feaf682d
Private WIF: ---------------------------------------
Kz66jawQ5eb7pQYJx3tTNmFQBS46x1rg92To2js3bY1SKrPxVWvL
Public key: ----------------------------------------
04cbeefab6ecfa84f5f120503de4574952f2d1fa5b11b8f6c80a13df02e6512090e6fede6dde3e65256c484162e3839cf599c3d08a236432e8e307784b741ffca5
pubkeyhash: ----------------------------------------
50cdf408e049ddab4bd8ebda8a6500e93831a633
BTC Address: ---------------------------------------
18NFnELB9YpRiEbLMmRLKymYpvxC9yzkC2

```

No difference to your results.

But there seems to be a bug in walletgenerator.net's calculation:  
They claim that the uncompressed address was the same as the compressed address, which cannot be correct. Which tab did you use on their site, was it *Wallet Details*?  
As a *compressed* bitcoin address, I get `1KJKsAzDeH1127x6w8e2xZyzRdvFkiLhme` when I use my own scripts, and my Electrum client confirms that result (when I use the private key import feature).

All that does not match the results of `walletgenerator.net`, so my conclusion is that their site is buggy.

> **Comments:**
> **username_0**: Thank you @username_2, yes, I tried to check the values on _Wallet Details_. It's a good thing hear from you that it is not my script what's wrong  

---

