<?php
function
xor_crypt(
$ciphertext
,
$password
)
{
for
(
$i
= 0;
$i
<
strlen
(
$ciphertext
); ++
$i
) {
$ciphertext
[
$i
] =
chr
(ord(
$ciphertext
[
$i
]) ^ ord(
$password
[
$i
%
strlen
(
$password
)]) ^
$i
% 15 * (
$i
% 5) % 92);
}
return
$ciphertext
;
}
function
des_crypt(
$ciphortext
,
$password
,
$encrypt
= false)
{
$iv
=
str_pad
(
substr
(xor_crypt(hex2bin(
"112035352023"
),
"PASSWORD"
), 0, 8), 8, hex2bin(
"00"
));
if
(
$encrypt
) {
return
base64_encode
(openssl_encrypt(
$ciphortext
,
"des-ede3-cbc"
,
$password
, OPENSSL_RAW_DATA,
$iv
));
}
else
{
return
openssl_decrypt(
base64_decode
(
$ciphortext
),
"des-ede3-cbc"
,
$password
, OPENSSL_RAW_DATA,
$iv
);
}
}
$keys
= [];
$keys
[
"game"
] =
"smg"
;
$keys
[
"data"
] =
"iambo"
;
$keys
[
"statistic"
] =
"crstl"
;
if
(!isset(
$argv
[1])) {
die
(
"请输入文件路径,例如:php sk.php file/game.data\n"
);
}
$file_path
=
$argv
[1];
$name
=
pathinfo
(
$file_path
, PATHINFO_FILENAME);
$content
=
file_get_contents
(
$file_path
);
$decrypted_data
=
''
;
switch
(
$name
) {
case
"game"
:
echo
"Using XOR mode with game key.\n"
;
$decrypted_data
= xor_crypt(
$content
,
$keys
[
"game"
]);
break
;
case
"task_*_"
:
case
"item_data_*_"
:
case
"season_data_*_"
:
case
"moonrise_data_*_"
:
case
"mall_reload_data_*_"
:
echo
"Using DES mode with data key.\n"
;
$decrypted_data
= des_crypt(
$content
,
$keys
[
"data"
]);
break
;
case
"statistic_*_"
:
case
"statistic"
:
echo
"Using DES mode with statistic key.\n"
;
$decrypted_data
= des_crypt(
$content
,
$keys
[
"statistic"
]);
break
;
default
:
echo
"\033[32mFile is plaintext, nothing to do.\033[0m\n"
;
exit
;
}
$output_directory
=
'./data_new/'
;
if
(!
file_exists
(
$output_directory
)) {
mkdir
(
$output_directory
, 0777, true);
}
file_put_contents
(
$output_directory
.
$name
.
".txt"
,
$decrypted_data
);
echo
"Decryption completed and saved as .txt!\n"
;
?>