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

    • ufukreis1212
      By ufukreis1212
      Hello, I am new members. Help me please. I want vbs convert to au3 .
      This vbs code : 
      'deneme Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") strOSArch = GetObject("winmgmts:root\cimv2:Win32_OperatingSystem=@").OSArchitecture Set objNetwork = CreateObject("Wscript.Network") Set wshShell = CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set oShell = WScript.CreateObject("WScript.Shell") proc_arch = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") Set oEnv = oShell.Environment("SYSTEM") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colMB = objWMIService.ExecQuery("Select * from Win32_BaseBoard") Set colCSes = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItemsx = objWMIService.ExecQuery( _ "SELECT * FROM Win32_VideoController",,48) '------------------------------------------------------------------- Set obj = GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory") i = 1 For Each obj2 In obj memTmp1 = obj2.capacity / 1024 / 1024 TotalRam = TotalRam + memTmp1 i = i +1 Next '-------------------------------------------------------------------- Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Architecture from Win32_Processor") For Each objItem in colItems if objItem.Architecture = 0 then strArchitecture = "x86" end if if objItem.Architecture = 9 then strArchitecture = "x64" end if next '-------------------------------------------------------------------- strComputer = "." ' Local computer strMemory = "" i = 1 set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory") For Each objItem In colItems if strMemory <> "" then strMemory = strMemory & vbcrlf strMemory = strMemory & "Bank" & i & " : " & (objItem.Capacity /1024 /1024) & " Mb" i = i + 1 Next installedModules = i - 1 Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray") For Each objItem in colItems totalSlots = objItem.MemoryDevices Next '---------------------------------------------------------------------- Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" ) Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem" ) For Each objItem in colItems strComputerDomain = objItem.Domain Next for each System in SystemSet For Each objItem in colItemsx For Each objProcessor in colProcessors For Each bbType In colMB MbVendor = bbType.Manufacturer MbModel = bbType.Product MsgBox "İşletim Sistemi : " & System.Caption & vbNewLine & _ "İşletim Sistemi Versionu : " & + System.Version & vbNewLine & _ "Windows Mimari Yapısı: " & strOSArch & vbNewLine & _ "Kullanıcı isminiz: " & objNetwork.UserName & vbNewLine & _ "Bilgisayar ismi: " & strComputerName & vbNewLine & _ "Çalışma Grubu: " & strComputerDomain & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Anakart: " & MbVendor & " " & "[" & MbModel & "]" & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Grafik Kartı: " & objItem.Caption & vbNewLine & _ "Driver Version: " & objItem.DriverVersion & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "İşlemci Üreticisi: " & objProcessor.Manufacturer & vbNewLine & _ "İşlemci İsmi: " & objProcessor.Name & vbNewLine & _ "CPU Mimarisi: " & strArchitecture & vbNewLine & _ "İşlemci Çekirdek sayısı: " & oEnv("NUMBER_OF_PROCESSORS") & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Toplam RAM: " & TotalRam & " MB" & vbNewLine & _ "Toplam Slot: " & totalSlots & vbNewLine & _ "Boş Slot: " & (totalSlots - installedModules) & vbNewLine & _ "Ramlerin bulunduğu slotlar:" & vbcrlf & strMemory,0,"deneme" Next Next Next Next please help me , thanks.
    • JuanFelipe
      By JuanFelipe
       
      Hello friends, I have a query, it happens that I have a matrix nxn, the first column of this contains each cell a number with 21 digits, when I pass this matrix to Excel I obviously write that number as 1,10016E + 20, I solved it by adding a * at the end of each cell, but I want it to be written as a text so that I do not have to remove that *, I searched in Google but could not find an effective solution, thanks in advance. 
    • Puls3
      By Puls3
      Hi, This is my first post on the AutoIt Forums, I most of the time was able to get help from this community by merely searching though google and have been able to solve hundreds of problems this way, though in this case I was incapable of finding a solution to my problem. I am quite confident that it is a user error (And my fault) but I haven't been able to determine what I did wrong, any and all help would be greatly appreciated! I have uploaded my whole script pardon passwords to provide as much information as possible.
      I declared a global array at the top of the script and am having issues when I try to set it's value, and I fail to understand why.
      Error Message:
      "D:\Projects\AutoIt\Arena\Base.au3" (270) : ==> Subscript used on non-accessible variable.:
      $ExpMax[$i] = IniRead($TempSavePath, "Combatant" & $i, "ExpMax", $ExpMax[0])
      $ExpMax^ ERROR
      ConsoleWrite Log:
      Ran.
      Checking launch parameters.
      No launch parameters.
      Initiating load.
      Checking for save file.
      Save file not found.
      Load canceled.
      Loading or creating Combatant 1
      Base.au3
    • RamDemon
      By RamDemon
      Hi,
      Did anyone tried to  use Redis  with AutoIT as store DB ?
       Redis <-- more about it
      Mladen
    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
×