Title: | -={ H A C K E R S }=- |
Notice: | Write locked - see NOTED::HACKERS |
Moderator: | DIEHRD::MORRIS |
Created: | Thu Feb 20 1986 |
Last Modified: | Mon Aug 03 1992 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 680 |
Total number of notes: | 5456 |
What does the following .COM file do ? I promise it won't "hurt" you, so feel free to SAVE this note in a .COM file, edit out everything through the "cut here" line, and try it. Can anyone do it more simply ? Of course, no reading of files allowed from within the command procedure, lest the problem be trivial. ut here-----------cut here--------------cut here---------------cut here------ $ d1 = "qq[0,8] = 34" $ d2 = "q[0,8] = 39" $ d3 = "dol[0,8] = 36" $ d4 = "s[0,8] = 32" $ d5 = "dee[0,8] = 100" $ d6 = "e[0,8] = 61" $ d7 = "t = 1" $ d8 = "tlup:" $ d9 = "n = 1" $ d10 = "plup:" $ d11 = "d = d'n" $ d12 = "if t .eq. 1 then write sys$output dol, s, dee, n, s, e, s, qq, d, qq" $ d13 = "if t .eq. 2 then write sys$output dol, s, d" $ d14 = "n = n + 1" $ d15 = "if n .le. 17 then goto plup" $ d16 = "t = t + 1" $ d17 = "if t .le. 2 then goto tlup" $ qq[0,8] = 34 $ q[0,8] = 39 $ dol[0,8] = 36 $ s[0,8] = 32 $ dee[0,8] = 100 $ e[0,8] = 61 $ t = 1 $ tlup: $ n = 1 $ plup: $ d = d'n $ if t .eq. 1 then write sys$output dol, s, dee, n, s, e, s, qq, d, qq $ if t .eq. 2 then write sys$output dol, s, d $ n = n + 1 $ if n .le. 17 then goto plup $ t = t + 1 $ if t .le. 2 then goto tlup
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
95.1 | TURTLE::GILBERT | Wed Feb 13 1985 01:31 | 1 | ||
$ type 'f$env("PROCEDURE") | |||||
95.2 | VAXUUM::DYER | Wed Feb 13 1985 13:34 | 2 | ||
[RE .1]: You beat me to it! <_Jym_> | |||||
95.3 | SPRITE::OSMAN | Wed Feb 13 1985 14:29 | 11 | ||
You both ignored my statement in .0, saying: Of course, no reading of files allowed from within the procedure, lest the problem be trivial. Then again, perhaps you're responses weren't claiming to be "better solutions", but rather they answer the question "what does this .COM file do ?". If so, you get credit. By the way, from a theoretical computer language point of view, what sorts of languages allow such a program to be written and what do not ? | |||||
95.4 | PIXEL::PWONG | Wed Feb 13 1985 17:17 | 20 | ||
re: .1 ------ and then there is $ TYPE/OUT=TT TT or even $ COPY TT TT re: .3 ------ I've seen self reproducing programs in Basic, Fortran and C. I don't have it anymore but the Basic version used the same idea as the DCL procedure in .0. Here are a few short ones in C: * this one works almost everywhere: char*f="char*f=%c%s%c;main(){printf(f,34,f,34);}";main(){printf(f,34,f,34);} * cheating from UNIX main(){system("cat self.c");} - Paul | |||||
95.5 | FKPK::KONING | Wed Feb 13 1985 19:09 | 6 | ||
Re .3 last paragraph: I'd guess that any language that incorporates the notion of string datatype and output statements can do this. Then again, I shudder at the thought of trying it in COBOL. Interesting question: which language allows the shortest one? (APL freaks?) Paul | |||||
95.6 | TURTLE::GILBERT | Wed Feb 13 1985 23:29 | 11 | ||
re .3 Just answering the question. From a theoretical point of view, I believe that only the following features are needed: String variables String concatenation (if concatenation is only allowed on output, this should suffice) Iteration Ability to create/write a 'compilable' source | |||||
95.7 | EDSVAX::CRESSEY | Thu Feb 14 1985 10:31 | 28 | ||
my 2 cents worth: I think that the requirement that "strings of characters" be manipulable is only true if we restrict "programs" to be things constructed of strings of characters. If, for instance, we allowed program images to be thought of as "programs", then the ability to work with bits and bytes could replace the ability to work with characters and strings. Generically: It must be able to represent and manipulate data in the same form as the program itself. It must be able to execute a loop with a controlled exit. It must be able to transcribe data externally to itself. Has anyone ever seen a similar program for a general Turing machine that not only replicates itself, but also invokes the replica? Now if you come up with a program that not only replicates itself, but also performs a useful function, you are beginning to have something like DNA. Dave | |||||
95.8 | ORPHAN::BRETT | Thu Feb 14 1985 16:35 | 6 | ||
$loop: if .not. f$verify(1) then goto loop writes itself out... /Bevin | |||||
95.9 | SPRITE::OSMAN | Fri Feb 15 1985 11:12 | 18 | ||
Sorry, that's cheating, because f$verify is asking an external source to generate your output for you, which is as bad as reading the source file ! By the way, whoever sent in the on-line "C" program, congrads ! That one is correct. (I used DIFFERENCE command in DCL to verify it, and to verify my original solution. By the way, back on TOPS20 I wrote a BLISS program that printed itself out. Finally, when I thought I had succeeded, I used the TOPS20 equivalent of DIFFERENCES to verify my correctness. It did. THEN, just to be REALLY sure, I used DIRECTORY,@@CHECKSUM, and it showed differences !! So, I ended up having to fix my program some more, which was covertly putting in some extra nulls, which the DIFFERENCE utility on TOPS20 was missing. So, perhaps my solution or the C solution are still not correct ? Is there some equivalent to DIRECTORY,@@CHECKSUM on vms so we can be more sure ?) | |||||
95.10 | TURTLE::GILBERT | Sat Feb 16 1985 01:42 | 5 | ||
How about ... A C program that writes a Pascal program that writes the C program? You get the idea. | |||||
95.11 | SPEEDY::BRETT | Sun Feb 17 1985 09:16 | 3 | ||
Do a DUMP then a DIFF on the results.... /Bevin | |||||
95.12 | RANI::LEICHTERJ | Sun Feb 24 1985 21:47 | 21 | ||
The existence of self-reproducing programs is a very general result of the theory of recursive functions. In fact, if T(n) is the n'th Turing machine in some recursive enumeration, it is a corollary of the Recursion Theorem that there is an e with the property that, for all x, T(e)(x) = e; that is, machine e, on any input, simply prints e. All you have left then questions of representation - if I consider the number e to represent the program for its machine - i.e., I think of T as an interpreter - then, indeed, I have a self-reproducing automaton, without worrying about strings, characters, or anything of that sort - they are just syntactic gloss. It is also interesting to create chains of functions Fi such that Fi prints Fi+1 until finally some Fn prints F0. Or things like pairs of functions F and G such that F(G) = F and G(F) = G. There has been a lot of work about these kinds of questions in looking at how life began. There was an article about this in Scientific American a couple of years back. At first, there are single self-reproducing molecules. But it turns out that past a certain point, pairs, then triplets, gain an advantage in reproducing faster in the resulting distributions of "food" molecules. Beyond triplets, at the time, no one could compute what happens... -- Jerry | |||||
95.13 | SPRITE::OSMAN | Tue Feb 26 1985 17:10 | 21 | ||
It might be interesting to try this "the hard way", although probably NOT in dcl. First, notice that an EXTREMELY hard way is to write a decompiler, for instance the Smalltalk-80 decompiler. A decompiler could be probably written such that when modified to decompile itself rather than ask the user WHAT to decompile, it manages to print itself out. This solution, although EXTREMELY hard (in terms of effort needed to write a decompiler from scratch), is interesting because it isn't as likely to provoke the "so what?" response as my .COM solution does, since when you list it, you don't see many quoted strings in it. But we don't need to solve it the EXTREMELY hard way in order to have a program that prints itself out. We merely need to write the portions of a decompiler that know how to decompile the features of the language used within the program ! And we can limit our local variables to names like "t0, t1, t2 etc." to make it even easier. Perhaps such a self-printing program could be written in Bliss or C ? Any takers ? | |||||
95.14 | SPRITE::OSMAN | Tue Feb 26 1985 17:13 | 6 | ||
One of the previous responses alluded to functions whose output is different from the original function, such that executing the output produces the original function (or functions that do this in more than two steps). Can anyone write a .COM file whose output is NOT the original, but when the output is executed it produces the original ? | |||||
95.15 | OZONE::CRAIG | Wed Mar 06 1985 19:06 | 92 | ||
Re: Self-printing programs The process of writing a self-printing program is trivial in DSM (Digital Standard MUMPS). The Xecute command can force a program to load and print (or modify) itself, and then return control back to itself. Most MUMPS editors are variants of this idea (programs which modify other programs, or themselves). Herewith is an small example: SELF ;RSC ; Self-printing program XECUTE "ZLOAD SELF ZPRINT" QUIT For those of you unfamiliar with MUMPS, the quoted string after Xecute tells the interpreter to load the program named 'SELF' and print it to the current output device. The QUIT terminates the execution of the program. Something a little more useful along this line is a print utility I wrote a while back which will print any MUMPS routine (including itself) to any device. (Just about any MUMPS hacker you meet will have a program like this lying around somewhere. I've added comments to help those of you who don't know MUMPS, the comment marker is ";". Some special characters are "!" = linefeed, "?" = tab, "'" = NOT, "@" = indirection. All commands and functions (WRITE, SET, IF, $PIECE, $TEXT, etc.) are spelled in full here, in normal use they would be abbreviated to the first letter (W, S, I, $P, $T), which makes typing programs a lot easier!) UPRT ;R.S. CRAIG - Print selected routines WRITE !!,"Print Routines Utility",!! ; Get the output device (default = LPA0). DEV SET %DEF="LPA0:",%QTY=2 DO ^%IOS ; No device (%ZIOD) selected, stop routine. IF '$DATA(%ZIOD) SET %ZIOD="" GOTO EXIT ; Select right margin of 80 or 132, depending on device in %ZIOD. SET ROU="",RM=$SELECT(%ZIOD["LPA0":130,1:80) ; Call utility to select routine(s). WRITE ! DO ^%RSEL IF '$DATA(%UTILITY) WRITE !?2,"No routines selected" GOTO EXIT COPY WRITE !!,"How many copies? 1",$CHAR(8) READ COPY IF COPY="" SET COPY=1 IF COPY="?" WRITE !?3,"Enter the number of copies to print of each program" GOTO COPY ; Set copy to 1 if less then/equal to zero. SET COPY=+COPY IF COPY'>0 SET COPY=1 ; Create executable variables LINE and HDR using MUMPS indirection. INIT FOR VARIABLE="LINE","HDR" SET @VARIABLE=$PIECE($TEXT(@VARIABLE),";;",2) ; Functions to get system date and time. SET DATE=$ZCALL(%CDATASC,+$HOROLOG,2),TIME=$ZCALL(%CTIMASC,$PIECE($HOROLOG,",",2),2) ; Format the time to civilized format. SET TIME=$PIECE(TIME,":",1,2)_" "_$PIECE(TIME," ",2) ; Function to get default VMS device and directory. SET SOURCE=$PIECE($PIECE($ZCALL(%PGMSHOW),",",1),"]",1)_"]" ; Some VT100 escape sequences for showing off. SET BOLD=$CHAR(27)_"[1m",NORMAL=$CHAR(27)_"[0m" WRITE !!,"Printing routines on ",%ZIOD,!! ; Loop through the array in alpha order, return routine names ; in ROU, call PRINT subroutine from FOR loop, COUNT tells us ; how many times we did the loop. FOR COUNT=0:1 SET ROU=$ORDER(%UTILITY(ROU)) Q:ROU="" DO PRINT ; Done with FOR loop, let us know how many we printed. USE 0 WRITE !!?3,COUNT," routine" WRITE:COUNT'=1 "s" WRITE " printed" IF COPY>1 WRITE " (",COPY," copies each)" ; All done, clean up and quit. EXIT CLOSE %ZIOD K I,DATE,TIME,%DTY,%IOD,%UTILITY,%DTY,%ZIOD K COPY,COUNT,CT,HDR,LINE,LN,PG,RM,ROU,SOURCE,BOLD,NORMAL WRITE ! QUIT ; PRINT ; Write routine names to terminal (device 0). USE 0 WRITE:$X>70 ! WRITE ROU ; eXecute string to load routine, initialize PG (page count), ; redirect output to device and eXecute code in LINE. XECUTE "ZL @ROU FOR COPY=1:1:COPY SET PG=0 USE %ZIOD XECUTE LINE" ; Redirect output back to terminal, write some spaces, ; and quit subroutine. USE 0 WRITE ?$X+(10-$LENGTH(ROU)) Q ; ; Executable code ; This line eXecutes HDR, loops through program text, writes the ; line tag (1st $PIECE), and line code (2nd $PIECE), keeps track ; of the line count and does header again if > 62. LINE ;;XECUTE HDR FOR I=1:1 SET LN=$TEXT(+I) QUIT:LN="" WRITE !,$PIECE(LN," ",1),?8,$PIECE(LN," ",2,99) SET CT=CT+1+($X\80) IF CT>62 XECUTE HDR ; This line increments page count, writes a formfeed, default ; device and directory, date and time, page count and bumps up line ; count. HDR ;;SET PG=PG+1 WRITE #,BOLD,ROU,?12,SOURCE," ",DATE," ",TIME,?RM-(7+$LENGTH(PG)),"Pg. ",PG,NORMAL,! SET CT=4 | |||||
95.16 | SPEEDY::BRETT | Wed Mar 06 1985 19:30 | 4 | ||
Its gotta be trivial to have a .COM file start of "$ I = 1", generate "$ I = 2" and for this second form to generate "$ I = 1"... /Bevin | |||||
95.17 | PAR44::PFAU | Thu Mar 07 1985 10:41 | 8 | ||
re: .15 That's no fair. You just loaded your source program and printed it out. Could you write a DSM program that will display itself without using ZLOAD? The code should be able to reproduce itself without access to the source. tom p | |||||
95.18 | RSTS32::BARTON | Wed Apr 24 1985 15:01 | 8 | ||
My apologies. I haven't looked at this file in a long time. Here is a very small DCL .COM file which prints itself. Have fun. ------------------------------Cut Here------------------------------------------ $ A[0,8] = 34 $ B = "$ A[0,8] = 34!/$ B = !AS!AS!AS!/$ C = F$FAO(B,A,B,A)!/$ WRITE SYS$OUTPUT C!/" $ C = F$FAO(B,A,B,A) $ WRITE SYS$OUTPUT C | |||||
95.19 | ORPHAN::BRETT | Wed Apr 24 1985 21:53 | 6 | ||
It doesn't print itself out - the resulting file has one record instead of three. /Bevin PS: I still think its really cute... | |||||
95.20 | SPRITE::OSMAN | Tue Apr 30 1985 10:48 | 9 | ||
Hey Barton, I like that one. I'll let the one-record business pass. One small gripe though. When I "@" it, I see an extra blank line that "TYPE" doesn't display. Can you fix this flaw ? /Eric | |||||
95.21 | RAYNAL::AUGERI | Fri Jun 21 1985 18:00 | 7 | ||
A slightly shorter version of Paul Wong's C program in reply .4 is: p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);} This version is 66 characters versus Paul's, which is 76 characters. Mike | |||||
95.22 | Whats this?!?!? | CURIE::DECARTERET | Thu Aug 06 1987 14:46 | 106 | |
What does this do. I found it in my LOGIN.COM after I SET H 0/LOG=MORE.LOG Z [62"p F > > [62;1"pP1;1;1;4{> __?~????/??@B????; ???oOOOO/???N????; OOOOOOOO/????????; ???}@@A?/???N????; ???~????/CGGF????; ???~????/???N????; ???}AAA?/???N????; ???~????/???FCCC?; AAA}????/???N????; ???~????/CCCF????; ???{A@??/???N????; ???~????/???BCG??; ?@A{????/???N????; ???~????/?GCB????; ?_ON????/??@M????; ???NO_??/???M@???; ???OoOOO/?????@AC; ???OWSQP/????????; @ACGO_??/??????@?; ???_OGC?/CA@?????; OOOOOOo?/??????@?; OOOOOO[?/????????; @ACGo???/GCA@????; ?}AAA???/?BAAA???; ??WWW???/????????; ??AAA}??/??AAAB??; GGG}GGG?/AAAAAAA?; ?OWSQOO?/?@@@@@@?; ?ggwkig?/?A@?????; ?OOQSWO?/?@@@@@@?; ???}@@A?/CGGF????; ???KK???/?BB??BB?; wCCwCCC?/?@@?@@@?; wCCwCCw?/?@@?@@??; OOOSOOO?/???@????; ?oKAKo??/BAAAAAB?; KScCcSK?/???@????; Wcd~dcW?/??ABA???; ?@~@@B??/?ABA????; OGGO__O?/????????; GCCGOOG?/@@@@@@@?; wCQQQCw?/?@AAA@??; ?CgOgC??/?@???@??; ?oKAKo??/BA???AB?; gkigikg?/?@A?A@??; ?gggikg?/????A@??; ?gggggg?/?AAAAAA?; A}AAA}A?/?B???B??; MO_}_OM?/??ABA???; ?CIIIC??/????????; AEiQAAA?/ABAAAAA?; ?SiiiO??/??AAA@??; ?KQQ}Q}?/????B?B?; _??_WEA?/?@A@????; wCAAACw?/AB???BA?; ?AQQQQA?/?AAAAAA?; CAA{AAC?/???B????; oGCCCCC?/?@AAAAA?; CCCCCGo?/AAAAA@??; wCAAACw?/B?????B?; }?????}?/?@AAA@??; ?oKAKo??/B?????B?; EW_?_WE?/??@A@???; ?GGGGGW?/????????; _OGGoOG?/?@AA@@A?; ?_WSQQk?/E@AAAA@?; ?GGO__W?/GCA@?@M?; ?_O[QaC?/?@AAA@??; ?ogggG??/?@AAAA??; _OOOoOg?/HEABAA@?; GCGo?_O?/??KN@???; GGoOGGo?/??B???N?; ???w????/???@AA@?; oggggo??/@AAAA@??; C{?_OG??/?B@@AA??; ?CCgO_??/AA@???B?; ?w????w?/E@AAAA@?; CcW??_[?/ABA@@???; CCcSGGo?/??@AAA@?; ?GwGGwG?/?A@??B??; _??w??_?/?@ANA@??; ??_OGGo?/KB??@@??; _OGGWgG?/@AAAA@??; OGGwGGC?/???BA???; ????????/????????; ???}PPA?/EGGF????; oG?_?Go?/@AA@AA@?; OgicCC??/?BAIIE??; Cw????w?/??@AA@??; cQIEEAA?/?@@DDB??; OwSOOOO?/??@?????; ?GC}CG??/???B????; OOOOSwO?/????@???; ?_?}?_??/??@B@???; \P1;1|23/1B;24/08;25/0A\ < | |||||
95.23 | NRADM2::MAXCIM | Al Cote | Thu Aug 06 1987 17:36 | 5 | |
Does your account get enabled for WPS when you log in? If so, and you are on a VT2%%, it's probably loading up your function keys... Al | |||||
95.24 | thats it!! | CURIE::DECARTERET | Thu Aug 06 1987 17:54 | 3 | |
That MUST be it. When I log in under a VT100, it doesn't do it. Thanks for the quick reply as not to keepp me in suspense. -=*>Jason<*=- | |||||
95.25 | greek character set ? | PILOU::BONGARTZ | Happy Hacker | Fri Aug 07 1987 05:40 | 24 |
re: .23 > it's probably loading up your function keys... Some more details: these escape sequences first identify your terminal type ( <esc>Z ), sets it to VT200 mode, 7 bit controls ( <ESC>[62;1"p ), requests that it sends only 7-bit codes ( <esc><space>F ), downline- loads a character set ( <esc>P1;1;1;4{> and all the sixel patterns that follow ), then defines the function keys F11,F12 and F13 to be <ESC>, <BS> and <LF> , respectively . The character set is quite funny, mostly composed of various math and other signs (sigma, omega, and a lot whose name and existence i never heard of before...) - might be greek alphabet , any greek out there care to check it ? You can activate that character set after you've loaded it (by typing the note .22) by sending <ESC>(> to your terminal. Hope that helps... Marc. | |||||
95.26 | It's all Greek to me... | JON::MORONEY | Welcome to the Machine | Fri Aug 07 1987 12:36 | 4 |
Judging from some of the symbols used, it's a math character set of some sort. Or maybe APL. -Mike | |||||
95.27 | TCS Maybe? | SERPNT::GULDENSCHUH | Chuck Guldenschuh | Fri Aug 07 1987 16:39 | 1 |
Most likely to be the Technical Character Set. | |||||
95.28 | ERIS::CALLAS | Strange days, indeed. | Mon Aug 10 1987 10:39 | 4 | |
Most definitely the TCS. WPS+ loads the TCS into a terminal with soft fonts. Jon |