Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this code produce "I love you" without any characters or digits?

Taken from - http://www.echojs.com/news/8518

How does this produce window.alert("I love you");? I understand how it can obtain I from Infinity, that's about it

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


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


             $.$_$]+      ($._$=
            $.$_[$.__$  ])+($.$$=(
           $.$+"")[$.__$])+((!$)+"")
           [$._$$]+($.__=$.$_[$.$$_
            ])+($.$=(!""+"")[$.__$
              ]) + ($._= (!""+"")                  
               [ $._$_]) +$.$_
                  [ $.$_$ ]+
                    $.__+


            $._$+    $.$;
          $.$$=$.$+(!""+"")
        [$._$$]+$.__+$._+$.$+
        $.$$;$.$=($.___)[$.$_]
         [$.$_];$.$($.$($.$$+
           "\""+$.$_$_+(![]+
             "")[$._$_]+
                $.$$$_+
                 "\\"+


        $.__$+    $.$$_+
      $._$_+$.__+"(\\\"\\"+
     $.__$+$.__$+$.__$+"\\"+
   $.$__+$.___+(![]+"")[$._$_]+
   $._$+"\\"+$.__$+$.$$_+$.$$_+
    $.$$$_+"\\"+$.$__+  $.___+
      "\\"+$.__$+$.$$$+$.__$+
        $._$+$._+".\\\"\\"+
          $.$__  +$.___+
            ")"+ "\"")
              ( ))(
                );

http://jsbin.com/OhisIQAW/1/edit

like image 354
rickyduck Avatar asked Feb 13 '14 13:02

rickyduck


1 Answers

I have translated the whole code:

$ = ~[];                
/*
 * $ = -1
 */

$ = {
    ___:++$,              // $.___  = $ = 0
    $$$$: (![] + "")[$],  // $.$$$$ = "false"[0]           = "f" unuse
    __$: ++$,             // $.__   = $ = 1
    $_$_: (![] + "")[$],  // $.$_$_ = "false"[1]           = "a"
    _$_: ++$,             // $._$_  = $ = 2
    $_$$: ({} + "")[$],   // $.$_$$ = "[object Object]"[2] = "b" unuse
    $$_$:($[$] + "")[$],  // $.$$_$ = "undefined"[2]       = "d" unuse
    _$$:++$,              // $._$$  = $ = 3
    $$$_: (!"" + "")[$],  // $.$$$_ = "true"[3]            = "e"
    $__:++$,              // $.$__  = $ = 4
    $_$: ++$,             // $.$_$  = $ = 5
    $$__: ({} + "")[$],   // $.$$__ = "[object Object]"[5] = "c" unuse
    $$_: ++$,             // $.$$_  = $ = 6
    $$$: ++$,             // $.$$$  = $ = 7
    $___: ++$,            // $.$___ = $ = 8
    $__$: ++$             // $.$__$ = $ = 9
};
/*
 * build digit and data
 */

$.$_ = 
    ($.$_ = $ + "")[$.$_$] +      // $.$_ = "[object Object]"
                                    // "[object Object]"[5]        = "c"
    ($._$ = $.$_[$.__$]) +        // $._$ = "[object Object]"[1] = "o"
    ($.$$ = ($.$ + "")[$.__$]) +  // $.$$ = "undefined"[1]       = "n"
    ((!$) + "")[$._$$] +          // "false"[3]                  = "s"
    ($.__ = $.$_[$.$$_]) +        // $.__ = "[object Object]"[6] = "t"
    ($.$ = (!"" + "")[$.__$]) +   // $.$  = "true"[1]            = "r"
    ($._ = (!"" + "")[$._$_]) +   // $._  = "true"[2]            = "u"
    $.$_[$.$_$] +                 // "[object Object]"[5]        = "c"
    $.__ +                        //                               "t"
    $._$ +                        //                               "o"
    $.$;                          //                               "r"
/*
 * $.$_ = "constructor"
 */

$.$$ = 
    $.$ +                 //             "r"
    (!"" + "")[$._$$] +   // "true"[3] = "e"
    $.__ +                //             "t"
    $._ +                 //             "u"
    $.$ +                 //             "r"
    $.$$;                 //             "n"
/*
 * $.$$ = "return"
 */

$.$ = 
    ($.___)[$.$_][$.$_];  // (0)["constructor"]["constructor"] 
/* 
 * $.$ = function Function(){ [native code] }
 */

$.$(                    // Function(
    $.$(                  //   Function(
        $.$$ +              //     "return
        "\"" +              //     "\""
        $.$_$_ +            //     "a"
        (![] + "")[$._$_] + //     "l"
        $.$$$_ +            //     "e"
        "\\" +              //     "\\"
        $.__$ +             //     "1"
        $.$$_ +             //     "6"
        $._$_ +             //     "2"
        $.__ +              //     "t"
        "(\\\"\\" +         //     "(\\\"\\"
        $.__$ +             //     "1"
        $.__$ +             //     "1"
        $.__$ +             //     "1"
        "\\" +              //     "\\"
        $.$__ +             //     "4"
        $.___ +             //     "0"
        (![] + "")[$._$_] + //     "l"
        $._$ +              //     "o"
        "\\" +              //     "\\"
        $.__$ +             //     "1"
        $.$$_ +             //     "6"
        $.$$_ +             //     "6"
        $.$$$_ +            //     "e"
        "\\" +              //     "\\"
        $.$__ +             //     "4"
        $.___ +             //     "0"
        "\\" +              //     "\\"
        $.__$ +             //     "1"
        $.$$$ +             //     "7"
        $.__$ +             //     "1"
        $._$ +              //     "o"
        $._ +               //     "u"
        ".\\\"\\" +         //     ".\\\"\\""
        $.$__ +             //     "4"
        $.___ +             //     "0"
        ")" +               //     ")"
        "\""                //     "\""
    )()                   //   )()
)();                    // )();
/*
 * Function(
 *   Function(
 *     "return\"ale\\162t(\\\"\\111\\40lo\\166e\\40\\171ou.\\\"\\40)\""
 *   )()
 * )();
 */

also you can read it from here: https://gist.github.com/mutoo/9003010

like image 82
Mutoo Avatar answered Nov 06 '22 05:11

Mutoo