我正在开发一个带有大字典的 Android 文字游戏 -
这些单词(超过 700 000 个)作为单独的行保存在文本文件中(然后放入 SQLite 数据库中)。
为了保护我的字典,我想用 md5 对所有长度超过 3 个字符的单词进行编码。 (我不会混淆短单词和带有罕见俄语字母的单词ъ
and э
,因为我想在我的应用程序中列出它们)。
这是我尝试运行的脚本Perl v5.18.2在 Mac 优胜美地上:
#!/usr/bin/perl -w
use strict;
use utf8;
use Digest::MD5 qw(md5_hex);
binmode(STDIN, ":utf8");
#binmode(STDOUT, ":raw");
binmode(STDOUT, ":utf8");
while(<>) {
chomp;
next if length($_) < 2; # ignore 1 letter junk
next if /жы/; # impossible combination in Russian
next if /шы/; # impossible combination in Russian
s/ё/е/g;
if (length($_) <= 3 || /ъ/ || /э/) { # do not obfuscate short words
print "$_\n"; # and words with rare letters
next;
}
print md5_hex($_) . "\n"; # this line crashes
}
正如你所看到的,我必须在 Perl 脚本的源代码中使用西里尔字母 - 这就是为什么我把use utf8;
在其顶部。
然而我真正的问题是length($_)
报告的值太高(可能报告字节数而不是字符数)。
所以我尝试添加:
binmode(STDOUT, ":raw");
or:
binmode(STDOUT, ":utf8");
但脚本然后就死了子程序入口处的宽字符在与print md5_hex($_)
.
请帮助我修复我的脚本。
我将其运行为:
perl ./generate-md5.pl < words.txt > encoded.txt
这是例子单词.txt为您提供方便的数据:
а
аб
абв
абвг
абвгд
съемка