3v4l.org

run code in 300+ PHP versions simultaneously
<?php $my_secret = sodium_hex2bin("da93b1db433cfb2efe490a1bb263e440b586b6167c20b86f14cd058515806940"); $my_public = sodium_crypto_scalarmult_base($my_secret); $scott_secret = random_bytes(32); $scott_public = sodium_crypto_scalarmult_base($scott_secret); $my_shared_with_scott = sodium_crypto_scalarmult($my_secret, $scott_public); $scott_shared_with_me = sodium_crypto_scalarmult($scott_secret, $my_public); echo 'An attacker can only see: ', PHP_EOL; var_dump([ 'my public' => sodium_bin2hex($my_public), 'scott public' => sodium_bin2hex($scott_public) ]); echo 'Together, we calculated a shared secret for encryption: ', PHP_EOL; var_dump([ 'I see' => sodium_bin2hex($my_shared_with_scott), 'Scott sees' => sodium_bin2hex($scott_shared_with_me) ]);

preferences:
30.3 ms | 405 KiB | 5 Q