Guest User

Palindrome + Download

a guest
Oct 21st, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. Writeup for:
  2. https://github.com/binarygolf/BGGP/issues/151
  3.  
  4. After a couple of false starts I decided to create an entry that would be cover both BGGP's (1) palindrome and (5) download past challenges.
  5.  
  6. To get a code palindrome, I settled on writing a Shell script which mirrored code to the right side of a # comment character, ie:
  7.  
  8. echo 1#1 ohce
  9.  
  10. I chose Shell as it's a powerful language I'm familiar with and you could do a lot with few bytes, so felt there was lots of
  11. opportunity to keep the number of bytes low. I built on this idea, by having a Shell script which was simply:
  12.  
  13. $@#@$
  14.  
  15. If in a file, this would expand all arguments passed to it on each $@, where not in a comment. ie, if this content was in a 6.sh file, then you would get the following response:
  16.  
  17. ./6-chrome.sh echo 1 2 3
  18. 1 2 3#@$
  19.  
  20. (Notice that the 1 2 3 arguments are expanded where we have the $@ to the left of the comment character, but they're not expanded in the same way within the comment itself. This was crucial and usage explained towards the end, below).
  21.  
  22. Now I could replace the "echo 1 2 3" to perhaps open Chrome and each argument I gave it would open as a tab with that value as the address bar value. However, I simply wanted to have 1 tab to show the number 6 plus download the content for challenge 5, so after a little crafting, came up with:
  23.  
  24. ./6.sh google-chrome "data:text/html,6<script>setTimeout(window.location='https://t.ly/3jGrK',5000)</script>"
  25.  
  26. This opens Chrome, with a single tab with the address bar value:
  27.  
  28. data:text/html,6<script>setTimeout(window.location='https://t.ly/3jGrK',5000)</script>#@$
  29.  
  30. Firstly, it has the "data" protocol and identifies the content type as "text/html", so now I can add my own HTML into this empty page. The first thing I added was 6, so the page would be an HTML page simply with the number 6. Next, I added a <script> tag to be able to inject JavaScript code into the HTML page and have it run. But I wanted to show 6 and then after a short pause show challenge 5's content, so a setTimeout of 5000ms was added.
  31.  
  32. To get the content for challenge 5, I remember back to what I did for my challenge 5 entry - using the https://t.ly/3jGrK short URL, which resolves to https://www.w3.org/services/html2txt?url=https://binary.golf/5/5 - a W3C service which turns HTML into text and outputs it. This was a perfect way to recycle an old challenge entry!
  33.  
  34. Now we had something that would show 6 for 5 seconds, then following that download the challenge 5 contents using the W3C service & output the contents.
  35.  
  36. As for the #@$ part of the address bar value? This is ignored, as anything from a # character onwards in a URL is seen as a fragment and as there's no matching fragment in the HTML page we have, no action is taken and it also never appears in the webpage either.
  37.  
  38. Hope you like the entry, all makes sense and thanks for reading. :)
Add Comment
Please, Sign In to add comment