+ 58

[ASSIGNMENT] ๐Ÿ† WHY THIS WORKS ๐Ÿ†

I've created a simple JS obfuscation. The challenge is to explain why this code works. Let's see if anyone can decode my obfuscation ๐Ÿ˜‰. https://code.sololearn.com/WsNVWfgW9egp/?ref=app

11th Feb 2018, 11:23 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
26 Answers
+ 31
@Swapnil โ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€Œโ€ŒSrivastava A little reverse engineering gets me this. document.body.innerHTML='hellothis is magic<br>i\'m c++' Utilizing a few invisible unicode characters as your string in the p tag; \u200d zero width joiner 8205 \u200b zero width space 8203 \u0020 space 32 Then splitting by \u200d and joining by '0' or \u0030 and splitting by \u200b and joining by '1' or \u0031 then splitting that result by " " you end up with the following binary string array; ['1100100', '1101111', '1100011', '1110101', '1101101', '1100101', '1101110', '1110100', '101110', '1100010', '1101111', '1100100', '1111001', '101110', '1101001', '1101110', '1101110', '1100101', '1110010', '1001000', '1010100', '1001101', '1001100', '111101', '100111', '1101000', '1100101', '1101100', '1101100', '1101111', '1110100', '1101000', '1101001', '1110011', '100000', '1101001', '1110011', '100000', '1101101', '1100001', '1100111', '1101001', '1100011', '111100', '1100010', '1110010', '111110', '1101001', '1011100', '100111', '1101101', '100000', '1100011', '101011', '101011', '100111'] Which is then converted into decimal values, which in turn are used to get the characters, that when joined together form the final above value. Nice trick. Here's the code in Python with the invisible characters converted to their unicode representations. Written in a non-complex way for a little easier understanding. https://code.sololearn.com/c4fPl64MPe1a
12th Feb 2018, 4:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 32
a great one, but i am out for any explanations ๐Ÿ‘๐Ÿ˜‰
11th Feb 2018, 12:19 PM
tooselfish
tooselfish - avatar
+ 32
๐Ÿ‘‰ https://ibb.co/dgxKMS ๐Ÿ‘ˆ //see the image ๐Ÿ˜จ 1)no role of js section and css section //U can remove them 2)why line 7 is so long ... its coming to next line /*U have used invisible unicode characters there , to hide "i'm c++ , magic" ... whatever*/ when U'll try backspacing in that line , U'll notice that while backspacing ... sometimes spaces come ...that accounts for the space between those words U r displaying in the output & more things U have written there 'include' ... //Swapnil , make some lessons on unicode,SL'll give U special badge for that
11th Feb 2018, 5:03 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 30
@swapnil he is always doing weird stuff..โœŒ๏ธ๐Ÿ‘๐Ÿ˜Ž accept my challenges & tell me if u r free 2 accept until limit
11th Feb 2018, 4:34 PM
๐ŸŒ›DT๐ŸŒœ
๐ŸŒ›DT๐ŸŒœ - avatar
+ 23
@Kim San I Thanks.
11th Feb 2018, 11:31 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 22
@Saksham Saxena if you are talking about making a android app with JavaScript then see this : https://code.sololearn.com/WZcEbcTeHPf3/?ref=app and if you are taking about c++ then I dont know. The code above is not actually c++. Actually, the c++ code there does nothing. It is just to confuse. Everything there is just done by JavaScript.
11th Feb 2018, 1:22 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 21
@Tim Thuma let me tell you <script type="c++"> does nothing.๐Ÿ˜‚
11th Feb 2018, 12:56 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 20
@Jay I know I've used split() and join() a lot. But, still it is not the answer to the challenge.
11th Feb 2018, 12:58 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 20
HINT : what's that <p> tag doing there ?
11th Feb 2018, 4:24 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 16
It's these two lines' fold: `#include`</script>` `#include <script type="c++">` I think first line declares a script and the second one tells us that we're gonna use c++. I guess that's all?
11th Feb 2018, 12:02 PM
Tim Thuma
Tim Thuma - avatar
+ 14
nice code๐Ÿ‘๐Ÿ˜Š
11th Feb 2018, 12:21 PM
M.h.yaghobi
M.h.yaghobi - avatar
+ 11
wow ๐Ÿ˜ฎ
11th Feb 2018, 11:59 AM
Alvian Muhammad
Alvian Muhammad - avatar
+ 10
it's don't work to me ๐Ÿ˜
11th Feb 2018, 12:16 PM
Vukan
Vukan - avatar
+ 10
This code is JavaScript,you can remove the c++ and write anything there,the magic is in the html script tag with the constructor.To be honest you'll have to explain this yourself๐Ÿ˜‚
11th Feb 2018, 4:00 PM
แ Œแ ŒCode X
แ Œแ ŒCode X - avatar
+ 9
this logic is simpler than it looks swapnil has just evily added so many logic to throw us off track!!๐Ÿ˜‚
11th Feb 2018, 4:02 PM
แ Œแ ŒCode X
แ Œแ ŒCode X - avatar
+ 5
do you know what is biggest obfuscation? this line => <!-- THE REAL CODE IS IN JS TAB -->
12th Feb 2018, 1:41 AM
code learner
code learner - avatar
+ 3
nice...... magic... with p taggg
11th Feb 2018, 7:25 PM
PSI
PSI - avatar
+ 3
but.. can u explain how u do it... how it is hidden...
11th Feb 2018, 7:27 PM
PSI
PSI - avatar
0
I don't know if you've changed the code, but actually it is not working on my code playground...
12th Feb 2018, 5:27 PM
Bruno Della Motta
Bruno Della Motta - avatar