tags:

views:

85

answers:

3

Does a quine print the ACTUAL code of the program i.e not obfuscated or does it print the obfuscated program?

+5  A: 

I don't think obfuscation has anything to do with it. Usually a quine prints the actual source code of the program itself.

Greg Hewgill
you mean ALL what the code has will be printed AS IT IS ?
fahad
@fahad exactly!
Amarghosh
He's thinking that it decompiles the machine code.
Hans Passant
Btw: wasn't there a big earth quake in your home town a few days ago? Everything okay?
Hans Passant
@Hans Passant: Thanks for asking, you're the first on SO :) All good here, house and contents (including people) are in fine shape. Power, water, and even internet was continuous here through the whole event (which wasn't true even a block away).
Greg Hewgill
+1  A: 

Here is an actual quine in standard C, found at Wikipedia:

main() { char *s="main() { char *s=%c%s%c; printf(s,34,s,34); }"; printf(s,34,s,34); }

You will notice that its structure is relatively straightforward. It uses a string constant containing the text of the program as both the format string and one of the values to be formatted by printf().

When compiled and run, it prints exactly that single line of code.

There are examples of quines in a variety of languages, including several more in C, at the wiki article.

RBerteig
+2  A: 

Suppose that you had a C program which prints an "obfuscated" or otherwise cosmetically modified version of its source. For example, suppose there's a difference in whitespace or variable names.

Then that program would not be a quine, since by definition a quine is a program which prints itself, and by "itself" we mean the exact same sequence of bytes. But the output of that program, once compiled, would print the same thing as the original program (since it's just a cosmetic variant), i.e. itself. So the output is a quine.

This sometimes eases the process of writing a quine - just write a "nearly-quine", which maybe doesn't get the formatting exactly right, run it once, and the output is your actual quine.

This is all assuming a quine in C. A quine in x86 machine code would have to output not its C source, but the same sequence of bytes that makes up the .exe file.

I'm not sure what you mean by "ACTUAL code" as opposed to "obfuscated code", but to test whether something is a quine or not, you have to decide what language it's supposed to be a quine in. Maybe by deciding that you can answer your own question - do you just want a quine in C, or a quine that has something to do with your obfuscator?

Steve Jessop