-
Notifications
You must be signed in to change notification settings - Fork 0
/
d10_2.php
57 lines (44 loc) · 1.19 KB
/
d10_2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
function array_swap(&$array, $offset, $length)
{
$arr_length = count($array);
for ($i = 0; $i < intval($length / 2); $i++) {
// Wrap around list
$index = ($offset + $i) % $arr_length;
$index_to = ($offset + $length - 1 - $i) % $arr_length;
$tmp = $array[$index_to];
$array[$index_to] = $array[$index];
$array[$index] = $tmp;
}
}
function str_to_ascii_sequence($input)
{
return array_merge(
array_map(function ($c) {
return ord($c);
}, str_split( ($input))),
[17, 31, 73, 47, 23]
);
}
$sequence = '102,255,99,252,200,24,219,57,103,2,226,254,1,0,69,216';
$lengths = str_to_ascii_sequence($sequence);
$list = range(0, 255);
$index = $skip = 0;
for ($i = 0; $i < 64; $i++) {
foreach ($lengths as $length) {
array_swap($list, $index, $length);
// Wrap around list
$index = ($index + $length + $skip) % count($list);
$skip++;
}
}
$hash = '';
foreach (array_chunk($list, 16) as $chunk) {
$xor = 0;
foreach ($chunk as $num) {
$xor ^= $num;
}
// convert to hex
$hash .= str_pad(dechex($xor), 2, '0', STR_PAD_LEFT);
}
var_dump($hash);