Obfuscated code challenge

ag0aep6g anonymous at example.com
Sun Mar 14 11:04:19 UTC 2021


On 14.03.21 02:31, Phillip Meyer wrote:
> See if you can figure out what this code does without running it ;)
> 
> import std;void main(){(*["clung/locks"].tee!(function(x){return 
> x;}).array.ptr).enumerate.map!(i=>mixin(cast(typeof({}))(6.8*13.3824)~"6r0d2a5 
> ".array.chunks(2).map!(i=>[i[0].to!string~":"~39~(i[1].to!string)~'\''][0]).join(",")~"]").get(i[0],i[1])).writeln;} 

First, format the code a bit:

----
import std;
void main()
{
     (*["clung/locks"].tee!(function(x) { return x; }).array.ptr)
     .enumerate
     .map!(i =>
         mixin(
             cast(typeof({}))(6.8 * 13.3824) ~
             "6r0d2a5 ".array.chunks(2)
             .map!(i => i[0].to!string ~ ":" ~ 39 ~ i[1].to!string ~
                 '\'')
             .join(",") ~
             "]"
         )
         .get(i[0], i[1])
     )
     .writeln;
}
----

Now piece by piece:

(*["clung/locks"].tee!(function(x) { return x; }).array.ptr)
-> "clung/locks"

":" ~ 39
-> ":'"

"6r0d2a5 ".array.chunks(2)
-> ["6r", "0d", "2a", "5 "]

["6r", "0d", "2a", "5 "].map!(...).join(",")
-> "6:'r',0:'d',2:'a',5:' '"

 From context, guess that `cast(typeof({}))(6.8 * 13.3824)` becomes 
char(6.8 * 13.3824) = char(91) = '['.

The mixin is now trivial:
mixin('[' ~ "6:'r',0:'d',2:'a',5:' '" ~ "]")
-> [6: 'r', 0: 'd', 2: 'a', 5: ' ']

The outer `map` effectively replaces characters in "clung/locks" with 
the values from the mixed in associative array. So:

"clung/locks"[6] = 'r' -> "clung/rocks"
"clung/rocks"[0] = 'd' -> "dlung/rocks"
"dlung/rocks"[2] = 'a' -> "dlang/rocks"
"dlang/rocks"[5] = ' ' -> "dlang rocks"

And there it is:

----
import std;
void main() { "dlang rocks".writeln; }
----


More information about the Digitalmars-d mailing list