TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Obfuscated 99 Bottles of Beer in C

3 pointsby marvinbornerover 1 year ago

1 comment

ksajover 1 year ago
That&#x27;s from a year ago. ChatGPT can add something new to this. I asked it to explain the code:<p>---<p>This C code appears to be a cryptic and obfuscated implementation that generates the lyrics for the classic &quot;99 Bottles of Beer&quot; song. The code employs various macro and obfuscation techniques, making it challenging to read and understand at first glance.<p>Here&#x27;s a breakdown of the key elements:<p>1. *Macro Definitions:* - `??=define _(please, help)`: Defines a macro `_` that replaces `please` with `help`. - `??=define _____(i, m, v, e, r, y) r%:%:m`: Defines a macro `_____` that concatenates the parameters with `r` in between.<p>2. *Main Function:* - The main function uses obfuscated code to generate and print the lyrics for the &quot;99 Bottles of Beer&quot; song. - The song lyrics are printed using a series of nested macros and expressions.<p>3. *Obfuscation:* - The use of obfuscation techniques, such as complex macro names and expressions, makes the code challenging to read and understand at first glance.<p>4. *Output:* - The program prints the lyrics to the console, representing the number of bottles of beer on the wall and the action of taking one down and passing it around.<p>Overall, this code is a playful and obfuscated way of implementing the &quot;99 Bottles of Beer&quot; song in C. If you have any specific questions about certain parts of the code, feel free to ask!<p>---<p>I asked it to strip off the obfuscation, and here&#x27;s what I get.<p>---<p><pre><code> #include &lt;stdio.h&gt; #define please ! #define help - #define bottles_on_the_wall bottles #define Take_one_down_pass_it_around printf(&quot;Take one down, pass it around,\n&quot;); void singSong(int bottles) { if (please(please(help(help(bottles- please(please(help(help(bottles,please(!bottles&lt;&lt;help(bottles-!!bottles)))))), help(help(help(!bottles&lt;&lt;!bottles))))))))) { printf(&quot;%d bottles of beer on the wall, %d bottles of beer.\n&quot;, bottles, bottles); } else { printf(&quot;%d bottle of beer on the wall, %d bottle of beer.\n&quot;, bottles, bottles); } Take_one_down_pass_it_around; if (please(help(bottles))) { printf(&quot;%d bottles of beer on the wall.\n\n&quot;, bottles); } else { printf(&quot;%d bottle of beer on the wall.\n\n&quot;, bottles); } } int main() { int bottles = 99; while (please(!(!help(help(help(bottles-please(help(help(bottles, please(!!bottles)))))))))) { singSong(bottles); } printf(&quot;Please let me die. Mercy, I&#x27;m in pain.\n&quot;); return 0; } </code></pre> ---<p>It doesn&#x27;t work. But it&#x27;s a good start. Ironically if you remove the extraneous ) in the first &#x27;if&#x27; statement, you only get the &quot;Please let me die...&quot; lol. So it&#x27;s close, but not close enough.