Author

Topic: OpenAI generated PHP code for Address/Key is NOT Working. Can anyone plz help? (Read 67 times)

jr. member
Activity: 96
Merit: 6
Life aint interesting without any cuts and bruises
https://bitcointalksearch.org/topic/ann-ethereum-welcome-to-the-beginning-428589  go there ask them.
Ps, OpenAI is just a dumb mockup, ask here again and tell her and you are getting wrong results, she'll probably say; my apology, here is the correct code, which again is a wrong code. Lol.
yup. This dude is not lying. I tried it. 1 week. Pisses me off so much.  If it's not indent issues..then they give you the correct code..but indentation issues again... I somehow realize too... That they are limited by the a certain number in their response. It always seem to cut off before completing the code.
copper member
Activity: 1330
Merit: 899
🖤😏
https://bitcointalksearch.org/topic/ann-ethereum-welcome-to-the-beginning-428589  go there ask them.
Ps, OpenAI is just a dumb mockup, ask here again and tell her and you are getting wrong results, she'll probably say; my apology, here is the correct code, which again is a wrong code. Lol.
full member
Activity: 214
Merit: 278
I am trying to get a standalone PHP code without any external dependency to generate an Ethereum address/key pair. So I asked OpenAI ChatGPT to write the code for me. I got two different versions from it...

Version 1

Code:
include "keccak.php";
use kornrunner\Keccak;

// Generate a random private key
$private_key = bin2hex(openssl_random_pseudo_bytes(32));

// Compute the public key from the private key using elliptic curve cryptography
$public_key = '0x'.bin2hex(gmp_export(gmp_mul(gmp_init('0x'.bin2hex(openssl_random_pseudo_bytes(32)), 16), gmp_init('0x'.bin2hex(gmp_powm(gmp_init(2), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0', 16), gmp_init('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A1', 16))), 16))));

// Compute the Keccak-256 hash of the public key (as a hex string)
$address = '0x' . substr(Keccak::hash(hex2bin(substr($public_key, 2)), 256), -40);

echo "Private key: $private_key
";
echo "Address: $address
";

Version 2

Code:
include "keccak.php";
use kornrunner\Keccak;

function generate_ethereum_address() {
// Generate a new private key
$privateKey = bin2hex(random_bytes(32));
echo "Private Key: " . $privateKey. "
";

// Derive the public key from the private key
$publicKey = hex2bin('04' . str_pad(gmp_strval(gmp_init(substr($privateKey, 0, 64), 16), 16), 64, '0', STR_PAD_LEFT) . str_pad(gmp_strval(gmp_init(substr($privateKey, 64), 16), 16), 64, '0', STR_PAD_LEFT));

// Generate the Ethereum address from the public key
$address = '0x' . substr(Keccak::hash(substr($publicKey, 1), 256), -40);

// Return the Ethereum address
return $address;
}

// Generate an Ethereum address
$address = generate_ethereum_address();

// Output the Ethereum address
echo "Address: " . $address. "
";

For Keccak, this code is used - https://github.com/kornrunner/php-keccak/blob/main/src/Keccak.php

Sample o/p of Version 1 is...
Code:
Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8
Address: 0x753215ef5214d2494df5e19dafa5644d034d201c

Sample o/p of Version 2 is...
Code:
Private key: 1941069a40cc71a83b8df773e0b45cdb8aa70b748710c82eace662c07ede4cf8
Address: 0x753215ef5214d2494df5e19dafa5644d034d201c

Clearly, address generated by both versions are wrong and AI is unable to fix the code. Can any of you please fix it?
Jump to: