Pergunta

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

Foi útil?

Solução

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

Outras dicas

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?

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.

Following is a simple quine code. This source code need to saved as "quine_file.c". Compile and execute.

Here a simple file pointer is taken and it is used to read the source file line by line and print it to the stdout.

#include <stdio.h>
#include <stdlib.h>

void main()
{
      FILE *fp = NULL;
      char * line = NULL;
      int len = 0;
      int read;
      fp = fopen("quine_file.c","r");
      if(fp == NULL)
           return;
      while ((read = getline(&line, &len, fp)) != -1) 
      {
           printf("%s", line);
      }
      fclose(fp);
      if (line)
          free(line);
      exit(EXIT_SUCCESS);
}
#include <stdio.h>
main(){
FILE* fp = fopen("printItself.c", "r");
int c;
while ((c = getc(fp)) != EOF)  putc(c, stdout);
}

Save it in a file named as printItself.c ... Problem with previous example is that if i add a line in program e.g int x; i will have to add it in the string also while taking care of newline and spaces etc ... but in this example you can add whatever you want.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top