Making and Breaking Ciphers with a Commodore 64 - Part 4: The PIN Program from Terminator 2
By Michael Doornbos
- 4 minutes read - 792 wordsA few minutes into Terminator 2, the young John Connor takes his Atari Portfolio out of his bag and inserts a foil covered card into an ATM machine and proceeds to crack a pin number and steal some cash from an unsuspecting account.
This is a movie prop and doesn’t really appear to do anything useful. It’s almost certainly just a script that runs on the Atari Portfolio, and just counts down some strings to make a “cool” effect.
It appears in the movie to take about 10 seconds.
I’ve seen some recreations of this where random numbers get printed on the screen until the pin is “cracked” (they just print a result, whatever it is). This is almost certainly what they did for the movie prop, but I thought it would be fun to actually try and implement something that does the guesses and looks for a “match”. It’s trivial, but at least it does SOMETHING. And looking for a match after doing some work IS something we’ll need later in this series so building a framework for that routine is appropriate here.
This pin cracker wouldn’t work in real life because an ATM machine wont let you infinitely guess the pin code. You get 2 or 3 and then it stops you. I don’t know what happened if you made too many guesses in 1991, but these days it will suck in your card and not give it back.
There is also the issue of printing to the screen. The print routine that actually shows the user the digits that are being tested is probably several orders (thousands?) of magnitude slower than the actual guesses themselves. Printing the results in real time to the user is a cool effect (to some people) but it slows down the processing dramatically.
For fun, let’s assume this ATM has the worst security imaginable and do it on the Commodore.
OMG where’s the Python Version
Since this technically doesn’t DO anything and is just a cool visual, we’re going to skip the Python version. All of the examples I’ve seen online just fake it, so it doesn’t make much sense to further study fakes here. I’ll be doing plenty of faking it for one post.
The sorta lame visual effect
Maybe I thought this effect was cool in 1991, but today all I can see is it’s weird cycle wasting. We’re going to recreate it anyway.
Random numbers
We need some random numbers to create the effect, so we’ll do a routine that returns digits 0-9 using the Commodore’s SID chip.
I used this method, from this magazine article from 1986 for the One Time Pad on a Commodore program I wrote that will be part 9 or 10 of this series, so we’ll just reuse it here because it returns reasonably random numbers.
setsound
lda #$ff
sta $d40e
sta $d40f
lda #$80
sta $d412
rts
getrand
.block
loop lda $d41b
cmp #$30
bcc loop
cmp #$3a
bcs loop ;get another if not between 0-9
sta zp2
rts
.bend
Now let’s print a bunch of random numbers and reduce the line size every so often to match the movie effect. (I know, kinda lame).
linect .byte 38 ; this seemed to match the movie closely
linedelay .byte 7 ; slow it down to match the movie
doeffect
.block
ldy #239
doline ldx #0
loop jsr getrand
lda zp2
jsr chrout
inx
cpx linect
bne loop
lda #13
jsr chrout
jsr reduceline
dey
bne doline
rts
.bend
reduceline
.block
lda linedelay
dec linedelay
bne ahead
dec linect
lda #7
sta linedelay
ahead
rts
.bend
Even on the Commodore 64 this went WAY too fast to mimic the movie prop so I’ve introduced a delay and ran it several times, adjusting in between until it felt like a similar speed.
“Crack pin”
Brute forcing a 4 digit pin even on a Commodore is trivial if you’re allowed unlimited guesses. I wrote a quick program to do it without printing to the screen and it goes through 10000 combinations (0-9999) so quickly I couldn’t even time it, so printing to the screen and then waiting for the next frame to draw, slows it down so we can at least see it.
crackpin
.block
loop sed
sec
lda result
sbc #1
sta result
lda result+1
sbc #0
sta result+1
cld
jsr display
lda result+1
cmp pin+1
bne ahead
lda result
cmp pin
beq done
ahead
jmp loop
done
ldx #24
ldy #12
clc
jsr plot
ldy #>foundtitle
lda #<foundtitle
jsr $ab1e
rts
.bend
The result
I’m very happy with the way this turned out. The grey on grey closely mimics the Atrari’s blue/grey on grey.
Next up
Part 5 will be on cracking nuclear codes so buckle up!