bash + iconv + DosBox/x86 machine code (104 97 96 95 characters)
echo ↾각슈삨₲ɻ庲錿ʴ⇍罋곹삄ૃ蘊尧⺓⺂粘ㄾ㸸ਾ岈⺎➉⸠粓蜊㹏褾鄮漧粐蠊蝜⾈葜⾇⼠⺂ꤧ樠獧惇|iconv -futf8 -tucs2>o.com;dosbox o*
I suggest to put this in a script in an empty directory, it's almost guaranteed that copy-pasting it in a terminal will break everything; even better, you can grab the script here ready-made.
Expected output: ![expected output](../../I/static/images/aa798f9b98a70c3fffb210ca8f293d3fefb636c43cc9c5021d39159158258681.png)
How it works
The bash part is just a launcher that uses iconv
to "decompress" a .com
file from the UTF-8 characters of the script and launches it with DosBox.
Notice that this poses some limitation on the content, as not all the input sequences can be interpreted as UCS-2 with iconv
not complaining; for example, for some reason many operations involving the bx
register broke havoc depending on the place where I used them, so I had to work around this problem several times.
Now, the Unicode thing is just to take advantage of the "character count" rules; the actual size (in bytes) of the script is way larger than the original .COM
file.
The extracted .com
file is
00000000 be 21 01 ac 88 c2 a8 c0 7d 0a b2 20 7b 02 b2 5e |.!......}.. {..^|
00000010 83 e0 3f 93 b4 02 cd 21 4b 7f f9 ac 84 c0 75 e4 |..?....!K.....u.|
00000020 c3 0a 0a 86 27 5c 93 2e 82 2e 98 7c 3e 31 38 3e |....'\.....|>18>|
00000030 3e 0a 88 5c 8e 2e 89 27 20 2e 93 7c 0a 87 4f 3e |>..\...' ..|..O>|
00000040 3e 89 2e 91 27 6f 90 7c 0a 88 5c 87 2e a6 7c 0a |>...'o.|..\...|.|
00000050 88 2f 5c 84 2e a8 7c 0a 87 2f 20 2f 82 2e 27 a9 |./\...|../ /..'.|
00000060 7c 0a 20 6a 67 73 c7 60 f3 0a 0a 00 ||. jgs.`....|
0000006c
and is 108 bytes long. The NASM source for it is:
org 100h
start:
; si: pointer to current position in data
mov si,data
; load the character in al
lodsb
mainloop:
; bx: repetition count
; - zero at startup
; - -1 after each RLE run
; - one less than each iteration after each "literal" run
; the constant decrement is not really a problem, as print
; always does at least one print, and there aren't enough
; consecutive literal values to have wraparound
; if the high bit is not set, we have a "literal" byte;
; we prepare it in dl just in case
mov dl,al
; then check if it's not set and branch straight to print
; notice that bx=0 is fine, as print prints always at least one character
; test the top two bits (we need the 6th bit below)
test al,0xc0
; to see if the top bit was set, we interpret it as the sign bit,
; and branch if the number is positive or zero (top bit not set)
jge print
rle:
; it wasn't a literal, but a caret/space with a repetition count
; space if 6th bit not set, caret otherwise
mov dl,' '
; exploit the parity bit to see if the 6th bit was set
jnp nocaret
mov dl,'^'
nocaret:
; lower 6 bits: repetition count
; and away the top bits and move in bx
; we and ax and not al because we have to get rid of the 02h in ah
and ax,3fh
xchg ax,bx
print:
; print bx times
mov ah,2
int 21h
dec bx
jg print
; read next character
lodsb
test al,al
; rinse & repeat unless we got a zero
jnz mainloop
end:
ret
data:
; here be data
incbin "compressed.dat"
; NUL terminator
db 0
All this is just a decompresser for compressed.dat
whose format is as follows:
- if the high bit is not set, print the character as-is;
- otherwise, the low 6 bits are the repetition count, and the second-highest bit specifies if it has to print a space (bit not set) or a caret (bit set).
compressed.dat
in turn is generated using a Python script from the original text.
The whole thing can be found here.
2"exactly this text": including the empty line at the beginning? including the empty line at the end? with a trailing new-line or without? (That is, 0, 1 or 2 new-.lines at the end?) – Martin Ender – 2014-07-04T19:21:30.177
@m.buettner the output should have exactly one leading line break and one trailing line break/new line. (and quotes if you can't avoid them) :) – xem – 2014-07-04T19:36:09.897
1That ASCII looks more like a Cricket shot to me – Mr. Alien – 2014-07-05T06:26:52.557
@Mr.Alien I saw it in Martin Kleppe's recent talk: https://speakerdeck.com/aemkei/jscamp-dot-ro-minified-javascript-craziness (video: https://www.youtube.com/watch?v=zy-2ruMHdbU)
– xem – 2014-07-05T06:30:13.667