Misc - Triglot
Last updated
Last updated
The challenge is straight forward - write a Perl-Python-JavaScript file-read polyglot. Firstly, let's write the file-read code for each language:
Combining Perl+Python:
This is simple, put the python code behind the '#' symbol and it will be treated as a comment by Perl. Similarly in python, the Perl code is treated as comment when put between the triple double quotes. Here's the hard part - that is invalid JavaScript.
Anyway, I modified the validation script slightly such that it prints the individual interpreter's output:
My final script is:
As you can see from the syntax highlighting, it mostly made use of '//' in JavaScript to comment most of the other code out. Other thing worth mentioning is the odd for loop. To be honest, I still don't quite understand how this loop works. There are only 2 expressions (notice there's only 2 semicolons) and I'd expect the 2nd expression to be a condition in a typical loop but it's not. The decrement is also done in the function itself rather than the 'for' statement. If anyone could explain to me how this works do reach out to me :)
This is a tough one with very little solves but I still attempted it because I did a similar challenge in HTB last year . I thought I could breeze past this real quick but it turned out to be more challenging than I thought.
I spent a good maybe 5 hours going nowhere until I found this post, .