jjencode、jjdecode
記号だけで任意のJavaScriptコードを実行できるようにするフィルタプログラムと、それを元のコードに戻すデコーダプログラム。ppencodeのような物。
特長:
実用的ですね。
alert("おはよう、世界!");
が
$_={_:+[],__:+[]};$_.__++;$_.___=$_.__+$_.__;$_.____=$_.___+$_.__;$_._____=$_.___<<$_.__;$_.______=$_.___*$_.___+$_.__;$_._______=$_.___*$_.____;$_.________=$_._____+$_.____;$_._________=$_.___<<$_.___;$_.__________=$_.____*$_.____;$_.$$=""+{};$_.$_=""+[][[]];$_.$=$_.$$[$_.______];$_.$+=$_.$$[$_.__];$_.$+=$_.$_[$_.__];$_.$+=(''+!$_)[$_.____];$_.$+=(''+!'')[$_._];$_.$+=(''+!'')[$_.__];$_.$+=$_.$_[$_._];$_.$+=$_.$$[$_.______];$_.$+=(''+!'')[$_._];$_.$+=$_.$$[$_.__];$_.$+=(''+!'')[$_.__];$_._$_=(''+!$_)[$_.__];$_._$__=$_.$$[$_.___];$_._$___=$_.$$[$_.______];$_._$____=$_.$_[$_.___];$_._$_____=$_.$$[$_._____];$_._$______=$_.$_[$_._____];$_.$$_=(''+!'')[$_.__]+$_._$_____+(''+!'')[$_._]+$_.$_[$_._]+(''+!'')[$_.__]+$_.$_[$_.__];$_.$$$=$_[$_.$][$_.$];$_.$$$($_.$$$($_.$$_+'"'+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_._______+$_.__)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_._______+$_._$___)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_._______+$_.______)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.________+$_.___)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.________+$_._____)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.___+$_._________)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.___+$_.___)+'\\'+$_.$_[$_._]+(''+$_.____+$_._+$_._____+$_._$_)+'\\'+$_.$_[$_._]+(''+$_.____+$_._+$_._______+$_._$______)+'\\'+$_.$_[$_._]+(''+$_.____+$_._+$_._________+$_._________)+'\\'+$_.$_[$_._]+(''+$_.____+$_._+$_._____+$_._______)+'\\'+$_.$_[$_._]+(''+$_.____+$_._+$_._+$_.__)+'\\'+$_.$_[$_._]+(''+$_._____+$_._$_____+$_.__+$_._______)+'\\'+$_.$_[$_._]+(''+$_.________+$_.______+$_._____+$_._$___)+'\\'+$_.$_[$_._]+(''+$_._$______+$_._$______+$_._+$_.__)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.___+$_.___)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.___+$_.__________)+'\\'+$_.$_[$_._]+(''+$_._+$_._+$_.____+$_._$__)+'"')())();
になる。
jjencode.rb
#!/usr/bin/env ruby header = (<<'.' $_={_:+[],__:+[]}; // グローバル変数$_を定義、$_._は0 $_.__++; // $_._は0、$_.__は1 $_.___=$_.__+$_.__; // $_.___は2 $_.____=$_.___+$_.__; // $_.____は3 $_._____=$_.___<<$_.__; // $_._____は4 $_.______=$_.___*$_.___+$_.__; // $_.______は5 $_._______=$_.___*$_.____; // $_._______は6 $_.________=$_._____+$_.____; // $_.________は7 $_._________=$_.___<<$_.___; // $_._________は8 $_.__________=$_.____*$_.____; // $_.__________は9 $_.$$=""+{}; // $_.$$は"[object Object]" $_.$_=""+[][[]]; // $_.$_は"undefined" $_.$=$_.$$[$_.______]; // $_.$は"c" $_.$+=$_.$$[$_.__]; // $_.$は"co" $_.$+=$_.$_[$_.__]; // $_.$は"con" $_.$+=(''+!$_)[$_.____]; // $_.$は"cons"、"false"[3]=="s" $_.$+=(''+!'')[$_._]; // $_.$は"const" $_.$+=(''+!'')[$_.__]; // $_.$は"constr" $_.$+=$_.$_[$_._]; // $_.$は"constru" $_.$+=$_.$$[$_.______]; // $_.$は"construc" $_.$+=(''+!'')[$_._]; // $_.$は"construct" $_.$+=$_.$$[$_.__]; // $_.$は"constructor" $_.$+=(''+!'')[$_.__]; // $_.$は"constrtor" $_._$_=(''+!$_)[$_.__]; // $_._$_=="a" $_._$__=$_.$$[$_.___]; // $_._$__ = "b" $_._$___=$_.$$[$_.______]; // $_._$___は"c" $_._$____=$_.$_[$_.___]; // $_._$____=="d" $_._$_____=$_.$$[$_._____]; // $_.$_____=="e" $_._$______=$_.$_[$_._____]; // $_.______=="f" $_.$$_=(''+!'')[$_.__]+$_._$_____+(''+!'')[$_._]+$_.$_[$_._]+(''+!'')[$_.__]+$_.$_[$_.__]; // $_.$$_="return" $_.$$$=$_[$_.$][$_.$]; // $_.$$$==Function . ).gsub(%r!\s*//.*|\n!, '') # コメントと改行を削除する def num2code(n) code = sprintf("%04x", n).split(//).map{|s| i = "abcdef".index(s) if i "$_._$#{ '_' * i.succ }" else "$_.#{ '_' * s.to_i.succ }" end }.join('+') "(''+#{ code })" end code = $stdin.read main =<<"." $_.$$$($_.$$$($_.$$_+'"'+#{ code.unpack('U*').map{|n| "'\\\\'+$_.$_[$_._]+" + num2code(n) }.join('+') }+'"')())(); . result = header + main puts result
jjdecode.js
Object.constructor = function (code) { alert(Function(code)()); }; // ここに記号化されたプログラムを貼る