Skip to content

Instantly share code, notes, and snippets.

@polonskiy
Last active August 8, 2016 11:12
Show Gist options
  • Save polonskiy/9c5b78d57b1237de8945 to your computer and use it in GitHub Desktop.
Save polonskiy/9c5b78d57b1237de8945 to your computer and use it in GitHub Desktop.
Repeating-key XOR encryption
<?php
$data = file_get_contents('php://stdin');
$password = 'ps8T0G/39oHgRehuV0TjUv2lyeA=';
$c = rkxor($data, $password);
$x = rkxor($c, $password);
var_dump($c,$x);
function rkxor($data, $password) {
$key = md5($password, true);
$key_len = strlen($key);
$data_len = strlen($data);
$cipher = '';
for ($i = 0; $i < $data_len; $i++) {
$cipher .= $data[$i] ^ $key[$i % $key_len];
}
return $cipher;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment