Jump to content
Sign in to follow this  
crashdemons

Quine Example

Recommended Posts

crashdemons

A Quine is a program that can output it's own source without having direct access or user intervention.

(This Means no reading of the script file, prompting for source input, packaging the source, or using inbuilt source references)

A Quine is not necessarily malicious or self-duplicating, but rather an attempt at a theory.

Definition of Quine

Why torture ourselves making this this way? The reason is to [re]prove a concept of computing: that it is possible for a turing-complete language to output it's own source-code. (or optionally, output a program in another language that outputs the original source code; aka. a multiquine )

Here, are some AutoIt3 Quines:

My Quines:

One-line quines from my reply on Page 2:

ConsoleWrite(StringReplace("ConsoleWrite(StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))",'%'&'s',Chr(34)&"ConsoleWrite(StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))"&Chr(34)))
MsgBox(0,'',StringReplace("MsgBox(0,'',StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))",'%'&'s',Chr(34)&"MsgBox(0,'',StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))"&Chr(34)))

Old 2-Line Quine:

$x="$x=%srnMsgBox(0,'Quine Example',StringFormat($x,Chr(34)&$x&Chr(34)))"
MsgBox(0,'Quine Example',StringFormat($x,Chr(34)&$x&Chr(34)))

Skeleton/Customizable Quine (Page 2)

Global $gsQuine
eq("MsgBox(0,'program','first exec line')")
eq("MsgBox(0,'program','second exec line')")
Func eq($s)
Execute($s)
$gsQuine&=BinaryToString(0x22287165)&$s&BinaryToString(0x0A0D2922)
EndFunc
$x="Global $gsQuinern%sFunc eq($s)rnExecute($s)rn$gsQuine&=BinaryToString(0x22287165)&$s&BinaryToString(0x0A0D2922)rnEndFuncrn$x=%srnMsgBox(0,'Quine Example',StringFormat($x,$gsQuine,Chr(34)&$x&Chr(34)))"
MsgBox(0,'Quine Example',StringFormat($x,$gsQuine,Chr(34)&$x&Chr(34)))

Any Questions? :)

Quines by Michel Claveau:

$x="MsgBox(0,'Quine','$x='&chr(34)&$x&chr(34)&@CRLF&$x)"
MsgBox(0,'Quine','$x='&chr(34)&$x&chr(34)&@CRLF&$x)

$g=chr(34)
$x="MsgBox(0,'Q','$g=chr(34)'&@CRLF&'$x='&$g&$x&$g&@CRLF&$x)"
MsgBox(0,'Q','$g=chr(34)'&@CRLF&'$x='&$g&$x&$g&@CRLF&$x)

Images of past quines:

Posted Image

Posted Image

- - -

And for my next magic trick :) - an AutoIt3 / PHP Polyglot (non-quine and all too simple)

A Polyglot is a script that can perform the same actions in multiple languages without manipulation of the code.

;=- <?php
;/*
ConsoleWrite(";=- Hello World -=;");
;*/
; echo "Hello World";
; ?> -=;

In either language, this outputs ";=- Hello World -=;" to the console.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
monoceres

Sorry for bumping, but I just had to.

Just read the wikpedia page on Quine and thought to myself: Hey! Wonder if it have been done in autoit? And indeed it had!

Very nice work (and in only 2 lines):)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Michel Claveau

Cool!

Share this post


Link to post
Share on other sites
NELyon

Is this correct?

Posted Image

Share this post


Link to post
Share on other sites
Merovingian

Is this correct?

Posted Image

Ugh huh you bet its correct *Grinz*

if in doubt read Quine Definition

Edited by Gargy

01000001 01110101 01110100 01101111 01001001 01110100 00100000
An immortal object must be copied, so that we get a mortal copy of it, since we try not to destroy immortal objects.

Share this post


Link to post
Share on other sites
NELyon

I thought the point was to output the whole source. There it only goes up to "MsgBox(0, 'Quine"

Share this post


Link to post
Share on other sites
Merovingian

I thought the point was to output the whole source. There it only goes up to "MsgBox(0, 'Quine"

You might have a vaild point there lets wait for Crash

lulz

*edit to conform

Edited by Gargy

01000001 01110101 01110100 01101111 01001001 01110100 00100000
An immortal object must be copied, so that we get a mortal copy of it, since we try not to destroy immortal objects.

Share this post


Link to post
Share on other sites
weaponx

First:

Stop centering the text in the posts, are newspapers and books center justified? No.

Second:

Just include the entire source code using FileInstall()

- or -

Using a preprocessor directive:

#AutoIt3Wrapper_res_SaveSource

See other options:

http://www.autoitscript.com/forum/index.ph...install++source

Edited by weaponx

Share this post


Link to post
Share on other sites
Tomb

You might have a vaild point there lets wait for Crash

lulz

your signature is soo big it makes the page have a sidewards scroollbar.

Share this post


Link to post
Share on other sites
monoceres

That depends on how big screen you have :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
crashdemons

Wow! don't think I've ever gotten this many replies.

Um yeah I think the $ before MsgBox was a typo when I was removing lines from it - I'll go fix it now.

Also, I'd be pleased if someone can make a different example

- although StringFormat is certainly easier than anything else I could think of.

wrapping the string in a function to try one-line makes it complicated, ugh because you have to repeat it 2+ etc.... *shrugs*

Let me know...

Shorter version of the "PHP/AutoIt" Polyglot (Editbox is broken on the first post)

;=- <?php /*
ConsoleWrite(";=- Hello World -=;");*/ echo "Hello World"; ?> -=;

PS:

I don't know exactly why it was only partially outputting for some - but just in case, try the newest edit that removed the extra '$' before MsgBox

-- also I noticed the icon on the dialog box where the problem is, I suppose it's possible there might be a compatibility issue with WINE? I don't know.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
Michel Claveau

Hi!

This release, without the StringFormat:

$x="MsgBox(0,'Quine','$x='&chr(34)&$x&chr(34)&@CRLF&$x)"
MsgBox(0,'Quine','$x='&chr(34)&$x&chr(34)&@CRLF&$x)

Variante:

$g=chr(34)
$x="MsgBox(0,'Q','$g=chr(34)'&@CRLF&'$x='&$g&$x&$g&@CRLF&$x)"
MsgBox(0,'Q','$g=chr(34)'&@CRLF&'$x='&$g&$x&$g&@CRLF&$x)

_

Edited by Michel Claveau

Share this post


Link to post
Share on other sites
crashdemons

Cool! that works good :)


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
weaponx

I am failing to see how this would be useful, you have to replicate every line of commands for running and outputting to the user. If you used something like this below you only have to define the code once:

$var = 'MsgBox(0,"","TEST")'

;Escape double quotes
$var = StringReplace($var, '"', '""')

;Format run command
$runCMD = StringFormat('"%s" /AutoIt3ExecuteLine "%s"', @AutoItExe, $var)

RunWait($runCMD)

Share this post


Link to post
Share on other sites
NELyon

Wait you want run autoit on linux with wine ?? i tried for years and fail

I've been running Autoit under wine for around 8 Months now :)

@Weaponx:

I don't believe there is supposed to be a point. I think it's more of a "See if I can" type of thing.

Share this post


Link to post
Share on other sites
Skrip

Sorry for bump, but can this output source as the line is called?

Like, script is on line 1, it shows only line 1, then it moves to 2, ect...


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites
crashdemons

Sorry for bump, but can this output source as the line is called?

Like, script is on line 1, it shows only line 1, then it moves to 2, ect...

do you want line 2 to output line 2 and line 3 to output line 3 ?

that sounds very difficult

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
crashdemons

here are two One-Line-Quines for Console and MsgBox

ConsoleWrite(StringReplace("ConsoleWrite(StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))",'%'&'s',Chr(34)&"ConsoleWrite(StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))"&Chr(34)))

MsgBox(0,'',StringReplace("MsgBox(0,'',StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))",'%'&'s',Chr(34)&"MsgBox(0,'',StringReplace(%s,'%'&'s',Chr(34)&%s&Chr(34)))"&Chr(34)))

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • JuanFelipe
      By JuanFelipe
      Hello friends, I have a simple question, can I have a variable that is not reset, even if my program is closed?
      That is, I want to make a program that can only be opened once, have a variable $ ini = 0, when it is opened for the first and only time it becomes $ ini = 1, so that it can not use the program a second time, as if it was a test software.
      I do not want the variable to depend on a reading of an external file that is easily manipulated. Thank you.
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
×