+52

[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

27 Answers

New Answer

+25

@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

+44

i dont know whats the content between the p tag.. .. the magic here .. <p id="sample">​​‍‍​‍‍ ​​‍​​​​ ​​‍‍‍​​ ​​​‍​‍​ ​​‍​​‍​ ​​‍‍​‍​ ​​‍​​​‍ ​​​‍​‍‍ ​‍​​​‍ ​​‍‍‍​‍ ​​‍​​​​ ​​‍‍​‍‍ ​​​​‍‍​ ​‍​​​‍ ​​‍​‍‍​ ​​‍​​​‍ ​​‍​​​‍ ​​‍‍​‍​ ​​​‍‍​‍ ​‍‍​‍‍‍ ​‍​‍​‍‍ ​‍‍​​‍​ ​‍‍​​‍‍ ​​​​‍​ ​‍‍​​​ ​​‍​‍‍‍ ​​‍‍​‍​ ​​‍​​‍‍ ​​‍​​‍‍ ​​‍​​​​ ​​​‍​‍‍ ​​‍​‍‍‍ ​​‍​‍‍​ ​​​‍‍​​ ​‍‍‍‍‍ ​​‍​‍‍​ ​​​‍‍​​ ​‍‍‍‍‍ ​​‍​​‍​ ​​‍‍‍‍​ ​​‍‍​​​ ​​‍​‍‍​ ​​‍‍‍​​ ​​​​​​‍‍‍​‍ ​​​‍‍​‍ ​​​​​‍ ​​‍​‍‍​ ‍​​​‍‍ ​‍‍​​​ ​​‍​​‍​ ​‍‍‍‍‍ ​​‍‍‍​​ ​‍​‍​​ ​‍​‍​​ ​‍‍​​​</p>

+31

👉 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

+30

a great one, but i am out for any explanations 👍😉

+29

cool code☺👍))

+29

@swapnil he is always doing weird stuff..✌️👍😎 accept my challenges & tell me if u r free 2 accept until limit

+22

+20

+20

@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.

+19

@Jay I know I've used split() and join() a lot. But, still it is not the answer to the challenge.

+19

+15

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?

+15

:) https://www.w3schools.com/jsref/jsref_split.asp https://www.w3schools.com/jsref/jsref_join.asp

+13

nice code👍😊

+11

+10

it's don't work to me 😁

+10

ohh thanks @Swapnil Srivastava

+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😂

+9

Now one question can this be used to create android app as many Sololearners have created. And if yes them how???

+9

this logic is simpler than it looks swapnil has just evily added so many logic to throw us off track!!😂