AS3 - 简单的文本加扰编码/解码器?

发布于 2024-12-15 06:28:01 字数 298 浏览 3 评论 0原文

我正在研究 AS3 游戏的保存/加载功能。我计划让玩家将浏览器运行的游戏保存到硬盘上。我想打乱我保存的文本,这样如果人们以文本形式打开文件,就无法真正阅读它。

有什么好方法可以在保存前对文本进行打乱,然后在打开后进行打乱?

我知道在 Java 中可以采用一个 char 并对其进行添加或减去来更改 char,这是一个非常简单的方法。在 ActionScript 3 中可以简单地完成什么?

请记住,我正在寻找简单和容易,而不是安全。我检查过的所有加密站点的解决方案都比我目前所能理解的更复杂,并且专注于进行最安全的加密而不是轻松集成。

I am working on the saving/loading functionality of my AS3 game. I plan to let the player save their game to their hard drive from a browser-run game. I want to scramble the text I'm saving so a human can't really read it if they open the file as text.

What is a good method to scramble text before saving, and then unscramble after opening?

I know in Java it's possible to take a char and add or subtract from it to change the char, which was an extremely simple method. What can be done simply in ActionScript 3?

Keep in mind, I'm looking for simple and easy rather than secure. All of the cryptography sites I've checked for solution are more complicated than I can understand at this point, and are focused on making the most secure encryption rather than on easy integration.

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

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

发布评论

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

评论(6

故乡的云 2024-12-22 06:28:01

可以做与 java 中类似的事情。

尝试:

var offset:int = 10;
for (i = 0; i < string.length; i++) {

string[i] = string.charCodeAt(i) + offset;

}

其中 string 是您要更改的文本,其作用是获取字符串每个索引处的字符的数字 unicode 值,并按偏移量修改其值。

要解码,请运行相同的代码,但方向相反:

for (i = 0; i < string.length; i++) {

string[i] = string.charCodeAt(i) - offset;

}

It is possible to do something similar to what you did in java.

Try:

var offset:int = 10;
for (i = 0; i < string.length; i++) {

string[i] = string.charCodeAt(i) + offset;

}

Where string is the text you want to change, what this does is gets the numeric unicode value of the character at each index of the string and modifies it's value by offset.

To decode you run the same code but in reverse:

for (i = 0; i < string.length; i++) {

string[i] = string.charCodeAt(i) - offset;

}
不醒的梦 2024-12-22 06:28:01

它可能会通过 fileReference.save() 获得一些原始主题,但我在这里寻找这个。实际上它再简单不过了:

var file:FileReference=new FileReference();
file.save(byteArrayData,"name you want to suggest to the user");

需要注意的一件事是:您只能在 mouseEvent (CLICK) 的处理程序内启动。
所以用户必须请求写入。
如果您尝试自动执行此操作,它将在本地工作,但一旦您将其放在网上,它就不会了!
似乎是一个相对较新且记录不良的安全功能。
因此,如果您最近在使用过程中遇到了困难,很可能就是这个原因。

这是一个在线工作示例,您可以通过按钮保存 PNG:
http://www.snoep.at/misc/youtube/cloud_generator/

为此要正常工作,您的用户需要相当新版本的 flashplayer(我认为是 10.1 及更高版本),因此如果它不起作用,您可以尝试更新。

It may be getting a bit of the original topic with the fileReference.save() but I got here searching for this. Actually it couldn't be simpler:

var file:FileReference=new FileReference();
file.save(byteArrayData,"name you want to suggest to the user");

One thing to watch: You can only initiate inside a handler of the mouseEvent (CLICK).
So the user has to request the write.
If you try to do it automtically it will work locally, but once you put it online, it won't!
Seems to be a relatively new badly documented security feature.
So if you had trouble making it work lately, it's probably that.

Here is a working online example, where you can save a PNG with a buttonpush:
http://www.snoep.at/misc/youtube/cloud_generator/

For this to work AT ALL your user need a fairly recent version of flashplayer (I think 10.1 and up), so if it doesn't work you might try an update.

白衬杉格子梦 2024-12-22 06:28:01

为什么不直接反转文本呢?这是一个简单而有效的方法。

另一种方法是将文本分成每组 2 个字符的组,然后反转它们,然后再次连接字符串。

Why not just reverse the text? That is a simple yet effective way.

Another would be to break the text in groups of 2 characters each, and reverse them, and then join the string again.

罪歌 2024-12-22 06:28:01

rot13 对此来说会很好而且很简单。我确信有一些 AS3 教程或 。 laziomatica.com/web/archives/61" rel="nofollow">那里。另一个常见选项是 base64,也可使用现有的

rot13 would be nice and simple for this. I'm sure there are a few AS3 tutorials or libraries out there. Another common option is base64, also with existing libraries.

春夜浅 2024-12-22 06:28:01

如果你真的想这样做,为什么不使用已建立的密码学密码呢?

从此处获取 as3crypto http:// code.google.com/p/as3crypto/downloads/detail?name=Crypto.zip&can=2&q=

那么这里是如何使用 RC4(众多您可以使用的密码):

import com.hurlant.util.Hex;
import flash.utils.ByteArray;
import com.hurlant.crypto.prng.ARC4;

var key:ByteArray = Hex.toArray("SUPER SECRET PASSWORD THAT YOUR USER WILL FIND OUT IF HE DECOMPILES YOUR SWF ANYWAY");
var pt:ByteArray = Hex.toArray("THIS IS THE ACTUAL FILE YOU'RE ENCRYPTING OR DECRYPTING");
var rc4:ARC4 = new ARC4(key);
rc4.encrypt(pt);
var out : String = Hex.fromArray(pt);
// save out to file

// load loadedFile from file
pt = Hex.toArray(loadedFile);
rc4.init(key);
rc4.decrypt(pt);
out = Hex.fromArray(pt);
// parse out's information

这可能看起来有点矫枉过正,但实际上它比制作自己的加密/解密更容易使用,并且它已经过测试和使用了很多次。

If you really wanna do this, why not use a established cryptography Cipher?

Get as3crypto from here http://code.google.com/p/as3crypto/downloads/detail?name=Crypto.zip&can=2&q=

Then here's how to use RC4 (one of the many ciphers you can use):

import com.hurlant.util.Hex;
import flash.utils.ByteArray;
import com.hurlant.crypto.prng.ARC4;

var key:ByteArray = Hex.toArray("SUPER SECRET PASSWORD THAT YOUR USER WILL FIND OUT IF HE DECOMPILES YOUR SWF ANYWAY");
var pt:ByteArray = Hex.toArray("THIS IS THE ACTUAL FILE YOU'RE ENCRYPTING OR DECRYPTING");
var rc4:ARC4 = new ARC4(key);
rc4.encrypt(pt);
var out : String = Hex.fromArray(pt);
// save out to file

// load loadedFile from file
pt = Hex.toArray(loadedFile);
rc4.init(key);
rc4.decrypt(pt);
out = Hex.fromArray(pt);
// parse out's information

This might seem a little overkill but it actually is easier to use than to make your own encryption/decryption thing, and it has been tested and used a bunch of times.

雪若未夕 2024-12-22 06:28:01

我不知道你如何保存游戏,但是如果你使用 本地共享对象,您的文本将保存为二进制数据(而变量名称仍然是人类可读的)。

I don't know how you save the game, but if you use Local Shared Objects, your text is saved as binary data (while variable names remain human readable).

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