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) ]);
Output for 7.1.0 - 7.1.21, 7.2.8 - 7.2.9
Fatal error: Uncaught Error: Call to undefined function sodium_hex2bin() in /in/DkmmI:3 Stack trace: #0 {main} thrown in /in/DkmmI on line 3
Process exited with code 255.
Output for 7.2.7
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "be9064c2974db3f3b781f94c3a84f18b401e6d49b7c0e3fcd64ed222d2568f07" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "df346f7a7c54fe5e1caf533125be726dc9bf0f817163c385a606bc3aec06241d" ["Scott sees"]=> string(64) "df346f7a7c54fe5e1caf533125be726dc9bf0f817163c385a606bc3aec06241d" }
Output for 7.2.6
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "d9216d9c119b1605f26b9a25d2d7b8734de833cfa70e0ab9fb12fe0070379745" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "a7cc65ea2bffffee9ddd86c228333b8c3872ce3da5b637f486388210f76d3266" ["Scott sees"]=> string(64) "a7cc65ea2bffffee9ddd86c228333b8c3872ce3da5b637f486388210f76d3266" }
Output for 7.2.5
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "ea31639fa9b72cbff3dc429f75c3e7ba48769fb537bb17e1455c9411bf86e434" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "aed8093d5729e45482aa02a8c43c24845621a530c7b4656c03f035758e605f2f" ["Scott sees"]=> string(64) "aed8093d5729e45482aa02a8c43c24845621a530c7b4656c03f035758e605f2f" }
Output for 7.2.4
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "8063a8c759f50a84ddd05ab70b21f0fc016ee9802d2a43457f7202ef18ce3814" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "9d3e7da40dc85f82f297640f2bd825a916c96e6c8a1f5e6907345ae21f58ae66" ["Scott sees"]=> string(64) "9d3e7da40dc85f82f297640f2bd825a916c96e6c8a1f5e6907345ae21f58ae66" }
Output for 7.2.3
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "094f925a08b58303d923d1a0ad4a25f5a92ec32ca37ba8c2fd0643460f84cd7f" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "78c731bb64027c0af78d7964a7e1848345f0a1a1ead5220ec7cb89ab6e314c61" ["Scott sees"]=> string(64) "78c731bb64027c0af78d7964a7e1848345f0a1a1ead5220ec7cb89ab6e314c61" }
Output for 7.2.2
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "b7759c6402a96efd7197bfaf3afdea0faac40e40de2d4a8e9ebb398d24c5eb46" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "9f9b6acd532d0984ab46c03f9513db463760a13942ca1f74060bb9fc02b68f6e" ["Scott sees"]=> string(64) "9f9b6acd532d0984ab46c03f9513db463760a13942ca1f74060bb9fc02b68f6e" }
Output for 7.2.1
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "0aa388c45efc7cf9ad446637c78ca28eb18e96f7076eab5a1d115fcc04c0155f" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "a788df604a31e80f9a756fc58cb06708c50cdcd7523c2cd224d2e6a986e7c465" ["Scott sees"]=> string(64) "a788df604a31e80f9a756fc58cb06708c50cdcd7523c2cd224d2e6a986e7c465" }
Output for 7.2.0
An attacker can only see: array(2) { ["my public"]=> string(64) "bfade946ef746beef397fbec6c1801d0337201c7a14f108f98c2d68a8232f027" ["scott public"]=> string(64) "b8c4acf241afc95f697938e565302594b8e229b9e71e969ab5c26fdcf24d4c6b" } Together, we calculated a shared secret for encryption: array(2) { ["I see"]=> string(64) "861e5067624b4739f61afcb0464966b1b008b6e7ab9e588f306c198c0532cb1b" ["Scott sees"]=> string(64) "861e5067624b4739f61afcb0464966b1b008b6e7ab9e588f306c198c0532cb1b" }

preferences:
47.98 ms | 402 KiB | 37 Q