奎因混乱。奎因实际上打印了什么?

发布于 2024-09-18 11:15:23 字数 41 浏览 10 评论 0原文

quine 打印程序的实际代码(即未混淆的代码)还是打印混淆的程序?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

爱*していゐ 2024-09-25 11:15:23

我不认为混淆与此有任何关系。通常 quine 会打印程序本身的实际源代码。

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

著墨染雨君画夕 2024-09-25 11:15:23

假设您有一个 C 程序,它打印其源代码的“混淆”或其他修饰版本。例如,假设空格或变量名称存在差异。

那么该程序就不是 quine,因为根据定义,quine 是一个打印自身的程序,而“自身”是指完全相同的字节序列。但是该程序的输出一旦编译,将打印与原始程序相同的内容(因为它只是一个装饰变体),即它本身。所以输出是一个 quine。

这有时会简化编写 quine 的过程 - 只需编写一个“nearly-quine”,它可能无法获得完全正确的格式,运行一次,输出就是您实际的 quine。

这一切都假设 C 语言中有一个 quine。 x86 机器代码中的 quine 必须输出的不是其 C 源代码,而是构成 .exe 文件的相同字节序列。

我不确定你所说的“实际代码”而不是“混淆代码”是什么意思,但是为了测试某个东西是否是奎因,你必须决定它应该是哪种语言。也许通过决定你可以回答你自己的问题 - 你只是想要一个 C 中的 quine,还是一个与你的混淆器有关的 quine?

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?

月下客 2024-09-25 11:15:23

这是标准 C 中的实际 quine,可在 Wikipedia 找到:

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

您会注意到其结构相对简单。它使用包含程序文本的字符串常量作为格式字符串和要由 printf() 格式化的值之一。

编译并运行时,它会准确地打印该行代码。

wiki 文章中提供了多种语言的 quines 示例,其中还包括一些 C 语言的示例。

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.

娇女薄笑 2024-09-25 11:15:23

以下是一个简单的 quine 代码。该源代码需要保存为“quine_file.c”。编译并执行。

这里使用一个简单的文件指针,它用于逐行读取源文件并将其打印到标准输出。

#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);
}

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);
}
爱殇璃 2024-09-25 11:15:23

quine 是一个打印自己列表的程序。这意味着当程序运行时,它必须精确地打印出程序员作为程序的一部分编写的那些指令(当然包括执行打印的指令以及打印中使用的数据)。

- David Madore

进一步阅读

示例

$=_=>`$=${$};$()`;$();

JavaScript 执行此程序将显示以下字符串

"$=_=>`$=${$};$()`;$();"

Featured in the art of code video@30米21秒
-迪伦·贝蒂

A quine is a program which prints its own listing. This means that when the program is run, it must print out precisely those instructions which the programmer wrote as part of the program (including, of course, the instructions that do the printing, and the data used in the printing).

- David Madore

Further reading

JavaScript example

$=_=>`$=${$};$()`;$();

when executed this program will display the following string

"$=_=>`$=${$};$()`;$();"

Featured in the art of code video @ 30m21s
- Dylan Beattie

恍梦境° 2024-09-25 11:15:23
#include <stdio.h>
main(){
FILE* fp = fopen("printItself.c", "r");
int c;
while ((c = getc(fp)) != EOF)  putc(c, stdout);
}

将其保存在名为 printItself.c 的文件中 ... 前面示例的问题是,如果我在程序中添加一行,例如 int x;我还必须将其添加到字符串中,同时处理换行符和空格等...但在这个示例中,您可以添加任何您想要的内容。

#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文