Last active
December 17, 2015 12:59
-
-
Save pbalduino/5613547 to your computer and use it in GitHub Desktop.
Obfuscation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; first I received this, and its result is 5. why? | |
((fn [[?<& %*+ $*|]](?<& %*+ $*|))({['*$] [+ (+ (*) (*)) (* 3 (*))]} ['*$])) | |
; so I formatted the code | |
((fn [[?<& %*+ $*|]] | |
(?<& %*+ $*|)) | |
({['*$] [+ (+ (*) (*)) (* 3 (*))]} ['*$])) | |
; ?<& is the first parameter, %*+ is the second and $*| is the last. let's rename to x, y and z | |
((fn [[x y z]] | |
(x y z)) | |
({['*$] [+ (+ (*) (*)) (* 3 (*))]} ['*$])) | |
; '*$ is an id of a hash item. let's call it 'id | |
((fn [[x y z]] | |
(x y z)) | |
({['id] [+ (+ (*) (*)) (* 3 (*))]} ['id])) | |
; if you evaluate (+ (*) (*)) alone, you will get 2, because (*) is 1, so (+ 1 1) equals 2 | |
((fn [[x y z]] | |
(x y z)) | |
({['id] [+ 2 (* 3 (*))]} ['id])) | |
; already knowing that (*) is 1, (* 3 (*)) means (* 3 1) that is equals 3 | |
((fn [[x y z]] | |
(x y z)) | |
({['id] [+ 2 3]} ['id])) | |
; let's attack the hash. we know that ({:id :value} :id) is :value, so ({['id] [+ 2 3]} ['id]) is [+ 2 3] | |
((fn [[x y z]] | |
(x y z)) [+ 2 3]) | |
; in the end, using destructuring, you're passing + as parameter to z, 2 to y and 3 to z, so you have (+ 2 3), that is 5 | |
(+ 2 3) | |
5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment