<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zhuolutetium on Medium]]></title>
        <description><![CDATA[Stories by Zhuolutetium on Medium]]></description>
        <link>https://medium.com/@zhuolutetium?source=rss-cd0a287d68a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zHFCALflqIWckuyg.jpg</url>
            <title>Stories by Zhuolutetium on Medium</title>
            <link>https://medium.com/@zhuolutetium?source=rss-cd0a287d68a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:08:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zhuolutetium/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Quick Look into Quines]]></title>
            <link>https://zhuolutetium.medium.com/a-quick-look-into-quines-b29fb4bffb69?source=rss-cd0a287d68a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b29fb4bffb69</guid>
            <dc:creator><![CDATA[Zhuolutetium]]></dc:creator>
            <pubDate>Fri, 02 Jul 2021 22:48:26 GMT</pubDate>
            <atom:updated>2021-07-02T22:48:26.917Z</atom:updated>
            <content:encoded><![CDATA[<p>I was first introduced to the idea of quines from the article “<a href="https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf">Reflections on Trusting Trust</a>” where the author, Ken Thompson, spoke about how he and his friends would compete to write the shortest quine. He said that it was their version of a video game. And as a college student who does play games and doesn’t want to be flexed on (at least too much) by his elders, I thought I would take a look into quines as well.</p><p>A quine is a program that outputs its source code without taking in any inputs. In his article, Thompson called it a “self-reproducing program.”</p><p>Most of the quines I’ve seen simply print out their source code to the console. And at least for my quick look, I’ll be satisfied by analyzing just that. However, in the grand scheme of things, this seems like a useless thing to do so I hope we can bring the concepts to other things later on.</p><p>No matter the language, there are usually two problems you need to solve to write a quine. To print the source code, you will have to recreate it as a string. This means that many of the instructions will be stored in a string variable, which will then become part of the program you are trying to print out. The quotation marks that enclose this string will become a problem as they will need to be escaped (for example \”), but the escape sequences you might want to use usually needs to be escaped as well. The other problem is that the newlines of the program will have to be escaped as well.</p><p>Now, we can see the reason why Thompson and his friends tried to write the shortest quine they could. The shorter it is, the less effort we will have to expend to recreate it.</p><p>Below, I show two versions in python and C that use different tricks to deal with the problem. We begin by first looking at the Python version as it’s pretty and readable.</p><h4>Python</h4><pre>n = &quot;print(&#39;n = &#39; + chr(34) + n + chr(34) + chr(10) + n)&quot;<br>print(&#39;n = &#39; + chr(34) + n + chr(34) + chr(10) + n)</pre><p>In python, the print statement is very simple, which alleviates some of the tedium of creating the string. In this case, we use the string n to describe most of the source code, which is basically just a print statement. We solve the problem of the escape sequences using chr(). In python, chr() takes in an integer and returns the ascii char represented by the number. In our case, chr(34) returns “ and char(10) returns a new line character. Using this, our print statement can deal with the escape character issue.</p><p>After python we go towards the less readable (and thus more of a flex) C.</p><h4>C</h4><pre>main(){char *c=&quot;main(){char *c=%c%s%c;printf(c,34,c,34);}&quot;;printf(c,34,c,34);</pre><p>In C, most of the standard quines look something like this. Note that this program is a single line and produce some compile warnings but would still run. This little program uses the same tricks that the python program used only with different syntax.</p><p>You can do a lot of quirky things with quines. In my searches, I saw a lot of programs that are shaped in an interesting way and they would print themselves in the same interesting way. Other quines print themselves backwards or as a palindrome. Not going to lie kind of sick. The one I was looking at was written by Dan Hoey. You might find other sick quine from the Obfuscated C Contest, which might be the funniest contest I’ve seen for programming so far.</p><p>Umm. How do you end a blog entry? Welp. Quines have been fun to play around with and this was really just a very quick look into them. I might look into them in more depth but that depends on if I find something interesting. They introduced me to some other topics that I want to blog about, so I want to work on them asap. See you then.</p><p>References:</p><p><a href="http://www.nyx.net/~gthompso/quine.htm">The Quine Page</a></p><p><a href="https://rosettacode.org/wiki/Quine#">https://rosettacode.org/wiki/Quine#</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b29fb4bffb69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>