发布于 2024-12-13 18:06:18 字数 1550 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2024-12-20 18:06:18

continue

XOR is a very simple, but quite effective, solution to this problem.

In GML:

/// script load_xor_file
// arguments: filename
// Prerequisite: Change the "key=" line to your chosen key
var key, kl, file, len, str, i;
key = "YOUR SECRET KEY HERE";
kl = string_length(key);
file = file_bin_open(argument0,0);
len = file_bin_size(file);
str = "";
for( i=0; i<l; i+=1) {
    str += chr(file_bin_read_byte(file) ^ ord(string_char_at(key,i mod kl + 1)));
}
file_bin_close(file);
return str;

/// script save_xor_file
// arguments: filename, data
// Prerequisite: Change the "key=" line to the SAME KEY as in load_xor_file
var key, kl, file, len, i;
key = "YOUR SECRET KEY HERE";
file = file_bin_open(argument0,1);
file_bin_rewrite(file);
len = string_length(argument1);
for( i=0; i<len; i+=1) {
    file_bin_write_byte(file, chr(string_char_at(argument1,i+1)) ^ chr(string_char_at(key,i mod kl + 1)));
}
file_bin_close(file);

I have never used RPG Maker myself, but I imagine it wouldn't be too hard to write similar code for it.

A couple of notes, it doesn't guarantee security. One could decompile the Game Maker EXE and reveal the key, or the key can just straight-up be broken if it is insecure.

A good, secure key is long, because breaking the encryption relies on the key repeating itself. If the key is the over half the length of the data being encrypted, it is virtually impossible to break the encryption, except by a known-plaintext attack if the file's contents are predictable (for example, I could assume the file contains the player's name and score, so those could be used in a known-plaintext attack).

Overall, this won't guarantee security of the file, but for your purposes should be more than suitable.

Also, since you were asking for a possible PHP solution:

<?php
function load_xor_file($filename) {
    $key = "YOUR SECRET KEY HERE";
    $in = file_get_contents($filename);
    $keyrep = str_repeat($key,ceil(strlen($in)/strlen($key)));
    return $in ^ $keyrep;
}
function save_xor_file($filename,$data) {
    $key = "YOUR SECRET KEY HERE";
    $keyrep = str_repeat($key,ceil(strlen($data)/strlen($key)));
    file_put_contents($filename,$data ^ $keyrep);
}
?>

PS. I know this question is fairly old, but I was just randomly browsing Game Maker tags :p

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文