#! /usr/local/bin/perl # # MOE16 encoder/decoder # (c) HIRATA Yasuyuki http://www.asuka.net/ # All rights reserved. # # This program is distributed in the hope that it will be useful, # but it comes with NO WARRANTY. # This file can be used, copied, destributed and changed freely # as long as copyright notice is not changed nor deleted. # # Typical usage: # % perl moe16 -e in_file > out_file (useful on MSDOS) # % perl moe16 -e < in_file > out_file (may not be used on MSDOS) # % perl moe16 -d out_file < in_file (useful on MSDOS) # % perl moe16 -d < in_file > out_file (may not be used on MSDOS) # # Requirements: # Perl Version 5 @moe = qw[萌え 小学 中学 少女 幼女 ロリ つる ぺた ぷに 眼鏡 動画 LD 猫耳 声優 水着 貧乳]; %moen = map { ($_, ++$i) } @moe; ($myname = $0) =~ s|^.+/([^/]+)$|$1|; if(($opt = shift) eq "-e") { &encode; } elsif ($opt eq "-d") { &decode; } else { print STDERR "$myname: ほえぇ〜 オプションが変だよぉ。\n"; } sub encode { my $count = 0; my $file = shift @ARGV; if($file) { open IN, $file or die; } else { *IN = *STDIN; } binmode IN; print "萌え開始\n"; while($c = ord getc IN) { $count++; foreach my $i (4, 0) { my $n = ($c >> $i) & 0xF; print $moe[$n]; print " " if($i || $count%8); } print "\n" if($count%8 == 0); } print "\n" if($count%8); print "萌え終了\n"; } sub decode { my $skip = 1; my $file = shift @ARGV; if($file) { open OUT, "> $file" or die; } else { *OUT = *STDOUT; } binmode OUT; while(<>) { s/\s+$//; if($skip && /^萌え開始/) { $skip = 0; } elsif(/^萌え終了/) { $skip = 1; } else { my($c, $d) = (0, 0); foreach my $s (split /\s+/) { if($moen{$s}) { if($c) { print OUT pack "C", ($d << 4) + ($moen{$s} - 1); $c = 0; } else { ($c, $d) = (1, $moen{$s} - 1); } } else { print STDERR "$myname: ほえぇ〜 変な文字列だよぉ。($s)\n"; } } } } }