Help us understand the problem. What is going on with this article?

誕生日を祝うとは()

More than 1 year has passed since last update.

JS記号プログラミング入門で遊びました...(狂気)。

想定

happybirthday.js
alert('Happy,Birthday!');

実装(結論)

symbol.js
(+[])[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]][({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]((!!{}+"")[-~[]]+(!!{}+"")[-~-~-~[]]+(!!{}+"")[+[]]+(!!{}+"")[-~-~[]]+(!!{}+"")[-~[]]+({}.$+"")[-~[]]+"\"\\"+-~[]+-~[]+-[]+(!{}+'')[-~[]]+(/ /[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]+[])[-~-~-~-~-~-~-~-~-~-~-~-~-~-~[]]+(/ /[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]+[])[-~-~-~-~-~-~-~-~-~-~-~-~-~-~[]]+(-~[]/[]+[])[-~-~-~-~-~-~-~[]]+','+"\\"+-~[]+-[]+-~-~[]+(-~[]/[]+[])[-~-~-~[]]+(!![]+[])[-~[]]+(!![]+[])[+[]]+"\\"+([][[]]+[])[+[]]+-[]+-[]+-~-~-~-~-~-~[]+-~-~-~-~-~-~-~-~[]+([][[]]+[])[-~-~-~-~-~-~-~-~[]]+(![]+[])[-~[]]+(-~[]/[]+[])[-~-~-~-~-~-~-~[]]+'!'+"\"")();

細かいことは↑の記事を読んでください。素晴らしい記事です。

そして気づいたら、alertじゃなくてconsoleになってました。以上です。

以下メモ欄(スクロールしても何もありません。ただのメモ書きです。)





























ネーム入り実装

happybirthday.js
(0).constructor.constructor("alert('Happy,Birthday!')")()

Functinオブジェクト

当然Numberオブジェクトでなくてもできますが、どうせ全部記号に置き換わることになるので、わざわざ荊の道をいく必要はないでしょう( ({}+'')[5].constructor.constructor('alert()')() Stringオブジェクト c (({}+'')[5])より生成(ただ無駄に長くなるだけ))。

console.js
>(0)
0

>(0).constructor
ƒ Number() { [native code] }

>(0).constructor.constructor
ƒ Function() { [native code] }

>(0).constructor.constructor()
ƒ anonymous(
) {

}

>(0).constructor.constructor('alert()')
ƒ anonymous(
) {
alert()
}

>(0).constructor.constructor('alert()')()
undefined // alert()の実行

で得られた関数をドット記法から、ブラケット記法に変換して、全て文字列にする。

happybirthday.js
(0)['constructor']['constructor']("alert('BB!Happy,Birthday!')")()
constructor.js
// c
console.log(({}+'')[5]);
// o
console.log(({}+'')[1]);
// n
console.log(({}.$+"")[1]);
// s
console.log((!{}+'')[3]);
// t
console.log((!!{}+'')[0]);
// r
console.log((!!{}+'')[1]);
// u
console.log((!!{}+'')[2]);
// c
console.log(({}+'')[5]);
// t
console.log((!!{}+'')[0]);
// o
console.log(({}+'')[1]);
// r
console.log((!!{}+'')[1]);

// constructor
({}+'')[5]+({}+'')[1]+({}.$+"")[1]+(!{}+'')[3]+(!!{}+'')[0]+(!!{}+'')[1]+(!!{}+'')[2]+({}+'')[5]+(!!{}+'')[0]+({}+'')[1]+(!!{}+'')[1]

alert.js
// a
console.log((!{}+'')[1]);
// l
console.log((!{}+'')[2]);
// e
console.log((!!{}+'')[3]);
// r
console.log((!!{}+'')[1]);
// t
console.log((!!{}+'')[0]);

// alert
console.log((!{}+'')[1]+(!{}+'')[2]+(!!{}+'')[3]+(!!{}+'')[1]+(!!{}+'')[0]);

大文字

普通に8進数で文字列を作ってもダメみたいなので、関数でreturnする

omoji.js
// B
console.log("\102");
// H
console.log("\110");

// B
console.log((0)["constructor"]["constructor"]((!!{}+"")[1]+(!!{}+"")[3]+(!!{}+"")[0]+(!!{}+"")[2]+(!!{}+"")[1]+({}.$+"")[1]+"\""+"\\"+1+-[]+-~-~[]+"\"")());

console.log((0)["constructor"]["constructor"]((!!{}+"")[1]+(!!{}+"")[3]+(!!{}+"")[0]+(!!{}+"")[2]+(!!{}+"")[1]+({}.$+"")[1]+"\""+"\\"+1+0+2+"\"")());

// BB

$=+[];$={___:$++,__$:$++,_$_:$++,_$$:$++};($.___)["constructor"]["constructor"]((!!{}+"")[$.__$]+(!!{}+"")[$._$$]+(!!{}+"")[$.___]+(!!{}+"")[$._$_]+(!!{}+"")[$.__$]+({}.$+"")[$.__$]+"\""+"\\"+-~[]+-[]+-~-~[]+"\\"+-~[]+-[]+-~-~[]+"\"")();

// BB!Ha

$=+[];$={___:$++,__$:$++,_$_:$++,_$$:$++};($.___)["constructor"]["constructor"]((!!{}+"")[$.__$]+(!!{}+"")[$._$$]+(!!{}+"")[$.___]+(!!{}+"")[$._$_]+(!!{}+"")[$.__$]+({}.$+"")[$.__$]+"\""+   "\\"+-~[]+-[]+-~-~[]+   "\\"+-~[]+-[]+-~-~[]+   "!"+   "\\"+-~[]+-~[]+-[]+   (!{}+'')[$.__$]+"\"")();

// p

(/ /[({}+'')[5]+({}+'')[1]+({}.$+"")[1]+(!{}+'')[3]+(!!{}+'')[0]+(!!{}+'')[1]+(!!{}+'')[2]+({}+'')[5]+(!!{}+'')[0]+({}+'')[1]+(!!{}+'')[1]]+[])[14]
$=+[];$={___:$++,__$:$++,_$_:$++,_$$:$++};($.___)["constructor"]["constructor"]((!!{}+"")[$.__$]+(!!{}+"")[$._$$]+(!!{}+"")[$.___]+(!!{}+"")[$._$_]+(!!{}+"")[$.__$]+({}.$+"")[$.__$]+"\""+   "\\"+-~[]+-[]+-~-~[]+   "\\"+-~[]+-[]+-~-~[]+   "!"+   "\\"+-~[]+-~[]+-[]+   (!{}+'')[$.__$]+ (/ /[({}+'')[5]+({}+'')[1]+({}.$+"")[1]+(!{}+'')[3]+(!!{}+'')[0]+(!!{}+'')[1]+(!!{}+'')[2]+({}+'')[5]+(!!{}+'')[0]+({}+'')[1]+(!!{}+'')[1]]+[])[14]+ "\"")();

// コピペしやすいように(メッセージ微妙に違います)

(+[])[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]][({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]((!!{}+"")[-~[]]+(!!{}+"")[-~-~-~[]]+(!!{}+"")[+[]]+(!!{}+"")[-~-~[]]+(!!{}+"")[-~[]]+({}.$+"")[-~[]]+"\""+"\\"+-~[]+-[]+-~-~[]+"\\"+-~[]+-[]+-~-~[]+"!"+"\\"+-~[]+-~[]+-[]+(!{}+'')[-~[]]+(/ /[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]+[])[-~-~-~-~-~-~-~-~-~-~-~-~-~-~[]]+(/ /[({}+'')[-~-~-~-~-~[]]+({}+'')[-~[]]+({}.$+"")[-~[]]+(!{}+'')[-~-~-~[]]+(!!{}+'')[+[]]+(!!{}+'')[-~[]]+(!!{}+'')[-~-~[]]+({}+'')[-~-~-~-~-~[]]+(!!{}+'')[+[]]+({}+'')[-~[]]+(!!{}+'')[-~[]]]+[])[-~-~-~-~-~-~-~-~-~-~-~-~-~-~[]]+(-~[]/[]+[])[-~-~-~-~-~-~-~[]]+','+"\\"+-~[]+-[]+-~-~[]+(-~[]/[]+[])[-~-~-~[]]+(!![]+[])[-~[]]+(!![]+[])[+[]]+"\\"+([][[]]+[])[+[]]+-[]+-[]+-~-~-~-~-~-~[]+-~-~-~-~-~-~-~-~[]+([][[]]+[])[-~-~-~-~-~-~-~-~[]]+(![]+[])[-~[]]+(-~[]/[]+[])[-~-~-~-~-~-~-~[]]+'!'+"\"")();






























終わりに

全然関係ないですけど、これ作ってる時に他のエンジニアの人にこれは見て楽しむものであって普通やらないからって言われましたまる

参考

記号だけのJavaScriptプログラミングの基本原理

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした