Bitcoin Forum
December 11, 2024, 10:37:21 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: OpenAI generated PHP code for Address/Key is NOT Working. Can anyone plz help?  (Read 76 times)
CounterEntropy (OP)
Full Member
***
Offline Offline

Activity: 214
Merit: 278


View Profile
February 18, 2023, 07:07:12 PM
 #1

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<br>";
echo "Address: $address<br>";

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. "<br>";

// 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. "<br>";

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?
digaran
Copper Member
Hero Member
*****
Offline Offline

Activity: 1330
Merit: 900

🖤😏


View Profile
February 19, 2023, 03:23:14 AM
 #2

https://bitcointalk.org/index.php?topic=428589.0  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.

🖤😏
krashfire
Member
**
Offline Offline

Activity: 127
Merit: 14

Life aint interesting without any cuts and bruises


View Profile
February 19, 2023, 10:30:37 AM
 #3

https://bitcointalk.org/index.php?topic=428589.0  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.

KRASH
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!