Skip to content

Instantly share code, notes, and snippets.

@kiironoaki
Created December 1, 2016 16:48
Show Gist options
  • Save kiironoaki/902329f5318a14de8a6e9b039b445d1d to your computer and use it in GitHub Desktop.
Save kiironoaki/902329f5318a14de8a6e9b039b445d1d to your computer and use it in GitHub Desktop.
Deffie-Hellman protocol sandbox
<?php
// private
$A = 15; // Alice
echo "Alice private key: " . $A . "(A)\n";
$B = 5; // Bob
echo "Bob private key: " . $B . "(B)\n";
// public
$a = pow(11, $A) % 23; // Alice
echo "\nAlice public key: " . $a . "\n";
$b = pow(11, $B) % 23; // Bob
echo "Bob public key: " . $b . "\n";
echo "\nFrom Bob: " . (pow($b, $A) % 23) . "\n";
echo "From Alice: " . (pow($a, $B) % 23) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment