Cracking the Agrippa Code

In 1992, cyberpunk author William Gibson published a 300-line poem on a 3.5″ floppy disk, titled Agrippa (A Book of the Dead). The poem was stored as a Macintosh program that, when run, would display the poem and then irreversibly encrypt itself, destroying the stored poem.

In 2012, I became interested in unlocking the encryption of Agrippa through the Agrippa Challenge, which enlisted the Internet to figure out the program. Here’s what I figured out.

The Agrippa program was developed in Macintosh Common Lisp, a dialect of Lisp augmented with routines to interface with the classic Macintosh OS of that era. Only the compiled binary was provided, and the source code has been lost to time.

On The Agrippa Files, a site dedicated to collecting information and resources related to Agrippa, there is an earlier draft version of the program’s source code:

Agrippa prototype code, page 3

Agrippa prototype code, page 5

The encryption algorithm there is a very straightforward in-house “encryption” algorithm that encodes data in 3-byte blocks. The design is clearly ad-hoc, and it does not reflect any known public cryptosystem; in particular, the reference to DES has nothing to do with the actual DES cryptosystem (the un-make-des function more closely resembles the RSA algorithm). This algorithm encodes data in 3-byte blocks. First, the 8 bits in each byte are permuted through a 8-position permutation (do-it), then the bits are split into two 12-bit integers (by taking the low 4 bits of the second byte and the 8 bits of the first byte as the first 12-bit integer, and the 8 bits of the third byte and the 4 high bits of the second integer as the second 12-bit integer). Each is individually encrypted by taking them to the 3491th power, mod 4097; the bits are then reassembled into 3 bytes.
Side note: 3491 appears nowhere in the code, but it is the exponent which reverses the action of taking the 11th power, mod 4097 (the implementation of un-make-des); that is, taking a number to the 3491th power mod 4097, then to the 11th power, again mod 4097, will result in the original number (mod 4097) for most integers. (This doesn’t work for numbers divisible by 17 or 241; evidently, the developer never ran into such values when using his encryption system as they would otherwise corrupt the text).
The 8 bits of the middle byte are permuted through a different 8-position permutation (do-too-it) and the three bytes are output as encoded bytes. The big block of data is the whole poem encoded with this algorithm and printed as MacRoman characters (with escapes, e.g. 0x5c, the slash character, is output as \\). Sadly, a combination of font and printing limitations means that the printout is not enough to directly decode the poem: several characters are unprintable (and so are “invisible” in the printout), there is no way to reliably distinguish tabs (0x09) from spaces (0x20), and some characters have been printed incorrectly by the font (e.g. the e in the repetitive " e\\" sequences should actually be an e with a circumflex (ê), but the printout doesn’t show this). Consequently, the poem can’t be completely recovered from the printout, but I am confident that the analysis is correct.
Note that the design of this algorithm ensures that any particular (aligned) block of 3 characters will encrypt the same way, since each block of 3 characters is independently encrypted. Thus, it exhibits a number of cryptographic weaknesses, primarily exhibited as regular patterns due to repeated text in the original plaintext.
A few sample encryptions:
Screenshot of an interactive Python session demonstrating sample decryptions
The encryption of three consecutive spaces is " ê\" (quotes added for clarity); since repeated spaces appear very often (e.g. before each chapter marker), this sequence can be seen repeated often.

The encryption of

tonight red lanterns are battered,

laughing,
in the mechanism.  

(the last few lines of the poem) is ΣÑÀQ$£¿Ì[ıƒ^ü…ïÓ êÊyMIÇ…~/ôì≈^Èür˙Q¯(ÀA}|yÙ¥3W+£¶ò∆©«ò\ which again matches the last few characters in the data block of the Lisp program listing.


Next, for the actual Agrippa program itself. I ran the programs in an emulator (Mini vMac), having no access to suitably old hardware myself.
The first major observation I made was that the application was compiled with a version of Macintosh Allegro Common Lisp dating back to 1989, possibly version 1.2.2 or 1.2.3. The application contains a bug which allows users to enter the Lisp REPL, a fully-featured interactive environment in which the code and data of the program can be directly manipulated. To exploit this bug, all you have to do is press some keys on the keyboard when the very first (empty) window appears. The bug is caused by a missing keyboard entry handler in that window; hitting keys on the keyboard should trigger the missing handler and result in an error. Upon any errors, the Lisp interpreter is configured to start its REPL:
A screenshot of Mini vMac showing the Agrippa debugger window
Exploiting this bug allows us to examine the program’s execution in much more detail than was previously possible. First, to get a mouse cursor, enter (_ShowCursor) at the prompt (with the parens and the underscore). Editing becomes easier after that. Typing (lisp-implementation-type) gives “Macintosh Allegro Common Lisp”, as expected. To get a list of *every* variable defined, type (apropos-list ""). This takes a long time to run – here’s what that output looks like:
A screenshot of the Agrippa debugger showing all of the built-in symbols
You can see some unusual names at the end, like shoot-gun, *mingzi*, *about-agri*, etc. (note that Lisp is not case-sensitive with its symbol or variable names). In fact, all variables after *TRACE-OUTPUT* are variables from the Agrippa program. Examining the Lisp code from the Agrippa Files, we see that many of the variable names are the same, but not all are. This immediately suggests that some variables were renamed, added or removed during the process of software development, implying that the Lisp listing was for an earlier pre-release version of the program.
The function UN-ROLL-ZI is suspicious, as it mirrors the name of un-roll-the-text in the original Lisp listing (in fact, “zi” means “words” in Chinese; a few variable names are named in languages other than English). However, the zi variable is not currently available. If you start the program again (from a fresh disk image, i.e. “for the first time”), and press keys when the poem window appears, typing in zi at the REPL will yield the complete, original text of the poem.
However, we are interested in establishing whether the encryption algorithm used to store zi in the Lisp program is the same as the one used in the older Lisp listing. In our original REPL, it turns out that the variable cl has the value 3, the same as the cell-length variable in the original listing. If we set cl to some other value, we can skip the decryption routine, allowing us to see the original “encrypted” data. I set cl to 10000 (larger than the poem itself), then used (continue). Agrippa dutifully begins to scroll a mountain of encrypted gibberish:
Screenshot of Agrippa scrolling encrypted junk.
and we can see the telltale " ê\" sequence in this screenshot. I can actually confirm that the decryption algorithm used in the Agrippa binary is functionally identical to the one implemented in the Lisp listing, i.e. that part of the program did not change between that listing and the final shipped version of the program. Therefore, the major mystery of “what encryption algorithm was used” has been solved.
There are a few more things to resolve:
  1. Scanning the binary for these encrypted strings turns up absolutely nothing. The reason is that the Macintosh Common Lisp compiler compresses the main program code into the executable, then fishes it out and decompresses it during startup. So, string searching will not turn up anything. The best bet if you want to get the encrypted mass of text is to use Linux ckpt or a similar tool to get a memory dump of Mini vMac after the Agrippa program has been loaded. The compression is not in any way a form of encryption, so we won’t discuss it in depth.
  2. What’s that mass of “encrypted” text that gets printed out at the end? From my observations I can tell it contains around 40 unique (printable) symbols, far short of the 96 one would expect to see for a properly encrypted piece of text (as an example, the original encrypted text has a lot more unique symbols compared to the garbage shown at the end). From experimentation, I suspect that the text is generated by applying the decryption algorithm again to the plain text to reduce it to gibberish. Here’s an example of that output:
    Screenshot of the junk printed out at the end of the Agrippa's execution.

    Later, I worked out that the plaintext poem is simply fed through the un-waymute-it (upp-it) function line-by-line, character-by-character, which effectively implements a simple substitution cipher over the characters. The characters are thus modified to become unrecognizable, but the encryption is trivially reversed by putting the text through waymute-it. Unfortunately, due to the limitations of the text display in the program, it is impossible to precisely determine the ciphertext (since some characters are replaced with boxes, and others are missing entirely); thus, “decrypting” the ciphertext that scrolls at the end is impossible to do precisely. However, since it’s a simple substitution cipher, the characters that are readable can be used to reconstruct at least part of the text.

  3. Why doesn’t the program run again the second time? This one’s pretty easy: the program corrupts itself at startup. Originally (as indicated in the Lisp program listing), the plan was to just write 40000 0xff bytes to the binary (“trash”), which would inevitably render the program “corrupt”. At some point, someone clearly thought it would be more artistic to use a “genetic code”, so the final version writes 6000 randomly-chosen (but fixed) As, Cs, Gs and Ts to a particular spot in the application file. This corrupts several routines in the program, preventing it from starting or running normally (or, depending on the computer used, freezing or crashing the whole system). Note that the genetic code has a codon entropy of 5.97 bits/codon, much higher than any natural DNA sequence known (they top out at around 4-5 bits/codon), and a BLAST nucleotide search turned up no results. It is therefore likely that it is randomly selected (or matched against an artificial DNA sequence, e.g. the sequence shown in the book).

Finally, I wrote some code to assist me in my reverse engineering efforts. It implements all the encryption and decryption routines, and further provides a demonstration decryption of the readable parts of the final encrypted text scroll (point #2 above).

# -*- coding: MacRoman -*-

pmq = 4097 # p-q
em2 = 11 # e-2
little = 16
lot = 256
cell_length = 3

def make_des(x): # reverse-engineered from un_make_des
    return pow(x, 3491, 4097) # 3491*11 = 1 mod 3840 (4097 = 17*241, 3840 = 16*240)

def un_make_des(x):
    return pow(x, em2, pmq)

def do_it(x): # reverse-engineered from un_do_it
    return (7-(x-5)*3) % 8

def un_do_it(x):
    return (3*(7-x)+5) % 8

def do_too_it(x): # reverse-engineered from un_do_too_it
    return (13-5*x) % 8

def un_do_too_it(x):
    return (5*(13-x)) % 8

def gen_permute(x, f):
    new = 0
    for temp in xrange(8):
        if x%2 == 1:
            new += 2 ** f(temp)
        x //= 2
    return new

def permute_it(x):
    return gen_permute(x, do_it)

def waymute_it(x):
    return gen_permute(x, do_too_it)

def un_permute_it(x):
    return gen_permute(x, un_do_it)
    '''
    new = 0
    for temp in xrange(8):
        if x%2 == 1:
            new += 2 ** un_do_it(temp)
        x //= 2
    return new
    '''

def un_waymute_it(x):
    return gen_permute(x, un_do_too_it)
    '''
    new = 0
    for temp in xrange(8):
        if x%2 == 1:
            new += 2 ** un_do_too_it(temp)
        x //= 2
    return new
    '''

def un_happenin(x1, y1, z1):
    this_num = un_make_des(x1 + (y1 % little) * lot)
    that_num = un_make_des((z1 * little) + (y1 // little))
    return (
        this_num % lot,
        (this_num // lot) + (that_num % little) * little,
        that_num // little
    )

def happenin(x1, y1, z1): # reverse-engineered from un_happenin
    this_num = make_des(x1 + (y1 % little) * lot)
    that_num = make_des((z1 * little) + (y1 // little))
    return (
        this_num % lot,
        (this_num // lot) + (that_num % little) * little,
        that_num // little
    )

def roll_the_text(the_text, wend=None): # reverse-engineered from roll_the_text
    '''
    Encrypt a piece of text with the "Agrippa cipher".
    Its length should be a multiple of 3.
    '''
    # default argument
    if wend is None:
        wend = len(the_text)

    num_cells = wend / cell_length

    new_text = []

    for rip_off in range(num_cells):
        c1 = chr(permute_it(ord(the_text[3*rip_off])))
        c2 = chr(permute_it(ord(the_text[3*rip_off+1])))
        c3 = chr(permute_it(ord(the_text[3*rip_off+2])))

        temp1, temp2, temp3 = happenin(ord(c1), ord(c2), ord(c3))
        new_text.append(chr(temp1))
        new_text.append(chr(waymute_it(temp2)))
        new_text.append(chr(temp3))

    return ''.join(new_text)

def un_roll_the_text(the_text, wend=None):
    '''
    Decrypt a piece of text using the "Agrippa cipher".
    Its length should be a multiple of 3.
    '''
    # default argument
    if wend is None:
        wend = len(the_text)

    num_cells = wend / cell_length

    new_text = []

    for rip_off in range(num_cells):
        c1 = the_text[3*rip_off]
        c2 = chr(un_waymute_it(ord(the_text[3*rip_off+1])))
        c3 = the_text[3*rip_off+2]

        temp1, temp2, temp3 = un_happenin(ord(c1), ord(c2), ord(c3))
        new_text.append(chr(un_permute_it(temp1)))
        new_text.append(chr(un_permute_it(temp2)))
        new_text.append(chr(un_permute_it(temp3)))

    return ''.join(new_text)

# "zi" variable dumped from vMac memory image
zi = '''
wWe7fG817qV9cXr1AlTJGo81NRq/n4ik+lH4mzpfNQh5BfvjAaVeASF5P4qmlwB9KyWzveuEmUTZ
jTAcu1tfggngk9U8vftUKjMbveuEmcbV6JBcIBYHMd2EqM11q2ZjIAQ6LMgZBax1IJBcG9+GgovA
uwaIIXH0hLV2zS416JBcIJBcve8CF1CjqDXJIed3uIPAj66pxiQDQmoPdsx9zM933MX6eUQ0z0l9
m8JMrcT6lf15fikOyDtXzE+NgDbufsz6dqITgKY4oAipgg9G66USNRz6fsoTuhj0fHn0AaNMfq3J
DTH0BPyUy1O/mO19zb4lPXL1vemk8INMDaNu6IKmlwB9fHn0nsCkEZ2UTRtfgovAgKLAfsz67kyz
k0ehBDD0I1qslOGkd3n0i+i/ghtHIeOeIAlClW+GmzpfNYjQmMJuAbEXHZJUl5AXDSdGJKtuF8JM
AbclblXJoIX6PWY1F9R2ceqmvemkblfiydyUuANKn4oTyCl9fHkh8HXJJc+pBPx5vev/IJnmu09J
xjAWi3qd6JIai3htNQh9fHn0CqO7govAfHn0+lfux8ITBHr18GfetDNHK6OeIAnRy1X6gCZJbtHm
7TNf7jXJB4uxdDOsHRJH66USk+44KyWzbsVetLPjcxx5xwyUoKtugKY40Gjg6IKmlxT6dspMAaEo
uhgvvW/etKehHB6uMdHvk8UmfOumIJR5btclgjP1IIAoi2oPdsx9zNl5IeOeflj0RRSauJU8uIPA
jYuEcXj06YuWgovAAbV5tDEoy0eNK7clBKaBoKtMEZ9y7jXJ8BXJ7sr/8yeZ7uzAoA7ni3z6OFj0
eUD9PXTV1q+Exx4Mov7VtlDb6BD9DI1ecXi4gDRnxqLAi+xeRlA8Mf12+lfuAad3F0In6Q+II8qe
8OMTRZSU6JIamzpfNQhCHRTJ9OqE6YuWIJDmNQh9giNGPXL1veuEDbeGi+53uIPAgDRhdjJHJc3J
NZqJ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KyF5j4qmcX4U7cLA1oum9Prjuo5rF9AZk+44ZItMIXO0pFfuk8G/
mcTDuhj0RRSay0FClW+GIIAoII84y9HmlX2aEYv/uIOEjZvjgKY4AbV5F8JMj4oTuhj0ZoG/daXN
z0l9fHn0CqZrDBK/uAM5NY6pxiZGpMOWbsOemzpfNQiT9lXJlPV5lxZEIXNXxqTNz0l9fHn0tDNX
K6OmmMapQibk8QGTP4qmlwB9IWX9Nk0DOp15DAB9HRTJF8KElqY4AbV5ve36i3z6ATNH+sOe6zNf
gh3Jd3n0CqRe+ld1+sEUmzpfgh3JB4m/ve36JU818HNHU+PATYvAlHd16IKmlwR2vyzZdLclzMue
IAl9h4OE6Z9yvf+6AWMnlxKeArvj+sc4I0h90lJfgKKe6zNfNQhC+tV58OV9+sc4Ue41mMC/n4x9
PXCU8wI5xjZ1I0o7zbjmcXr1IIKemzpfNRz6jaY18jvL8IXACjRnoDn0tlXJTRtf66OEy1EcJKPA
7Vv1F8RenxzJlX/uIJDmNQh5TQ9Jgh3Jfi+Zk8Ve6Z9y+lH4HBgoy0F9fHn0tDNXK6OmmMapx5hc
'''.decode('base64')

#print roll_the_text('   ').decode('mac-roman')
#print '-----'
#print roll_the_text('\rtonight red lanterns are battered,\r\rlaughing,\rin the mechanism.  ').decode('mac-roman')
#print '-----'
poem = un_roll_the_text(zi)
print poem.replace('\r', '\n').decode('mac-roman')

print '========================ENCRYPTED TEXT FOLLOWS======================'

enclines = [''.join(chr(un_waymute_it(ord(c))) for c in line) for line in poem.split('\r')]
delchars = '\x00\x02\x03\x04\x05' # invisible
boxchars = '\x01\x06\x07\x08\x0a\x0b\x0c\x0d\x0e\x0f' + ''.join(chr(i) for i in range(16, 32)) # these appear as boxes
box = u'\u25AF'
for page_start in range(19, len(enclines) - len(enclines) % 17, 17):
    print
    for line in enclines[page_start:page_start+17]:
        dispenc = line
        dispenc = dispenc.decode('mac-roman')
        for c in delchars:
            dispenc = dispenc.replace(c, '')
        for c in boxchars:
            dispenc = dispenc.replace(c, box)
        print dispenc
    print '------------------------[PAGE BREAK]----------------------------'

print '====================PARTIAL DECRYPTION========================'
ciphertext = '''•ù;•âã•©•ã••üπã9••ã••ù;•9••ãâ•;üèã©••ùõ••ù•;üô©•õ9•)••©ãúüª©çü;©
®•ãù•••;•ù•èã
∫ïòï•ö••;üù••9ï
•ùâ•;üèã©••ùõÖ••üèè•Ö
#'1°

®•ãù••ã•õç´ãâ•••;••üâ•••)9•ù©;•âüªù
•ù╪9ü©ã•´ùâã9•©•ãè
•ù••••ç•á畕㕪••©ã•)ãù••ç5
•(•)•ì;•;•ª•è•ççÖ••´õï•#'#'ï•'''
lines = ciphertext.split('\n')
for line in lines:
    print ''.join(chr(waymute_it(ord(c))) for c in line).decode('mac-roman')

This program prints out several pages of ciphertext. You can compare the generated encrypted text with the text that is scrolled during the last 25 seconds of the emulated run of Agrippa to see that the implemented encryption routine matches the original. Note that the last line of ciphertext on each “page” is not visible due to the limited height of the text display window. Finally, the script prints out a partial decryption of the first page of ciphertext based on what is visible (boxes have been replaced with • characters, which decrypt to <).

Previous Article
Next Article