forked from K-S-V/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimeDigital.php
47 lines (41 loc) · 1.44 KB
/
AnimeDigital.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
<?php
if ($argc < 2)
die("Usage: php AnimeDigital.php <encrypted_subtitles>");
// Read encrypted subtitles
$file = file_get_contents($argv[1]);
$file = base64_decode($file);
// Generate key
$td = mcrypt_module_open('rijndael-128', '', 'ecb', '');
$iv = str_repeat("\x00", 16);
$key = pack('H*', "32344150066d43644c5042725d");
$key = $key . str_repeat("\x00", 32 - strlen($key));
mcrypt_generic_init($td, $key, $iv);
$key = mcrypt_generic($td, $key);
$key = str_repeat(substr($key, 0, 16), 2);
mcrypt_generic_deinit($td);
/* PHP CTR mode wasn't working as intended so have to decrypt manually */
// Generate nonce for decryption
$encrypted = substr($file, 8);
$encLen = strlen($encrypted);
$blocks = ceil($encLen / 16);
$nonce = substr($file, 0, 8) . pack('N', 0);
// Decrypt subtitles
$decrypted = " ";
mcrypt_generic_init($td, $key, $iv);
for ($i = 0; $i < $blocks; $i++)
{
$enc = $nonce . pack('N', $i);
$dec = mcrypt_generic($td, $enc);
for ($j = 0; $j < 16; $j++)
{
if (!isset($encrypted[($i * 16) + $j]))
break;
$decrypted[($i * 16) + $j] = $dec[$j] ^ $encrypted[($i * 16) + $j];
}
}
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
// Save decrypted subtitles
$file = pathinfo($argv[1], PATHINFO_FILENAME) . ".ass";
file_put_contents($file, $decrypted);
?>