[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RC4 for HP48
-----BEGIN PGP SIGNED MESSAGE-----
Here is the RC4 cipher for the HP-48 calculator. It
complements the DES implementation by William E. Sommerfeld.
RC4 has a higher throughput than DES, but its key setup is
slower. The key may be up to 256 characters (2048 bits) --
the maximum supported by the RC4 algorithm.
Here are sample timings for a HP-48GX. The SX will be
correspondingly slower.
Key Setup (200 bits) 25.18 sec
RC4 throughput 5.06 cps
String to Array 61.83 cps
Array to String 56.12 cps
The HP-48 comes with a 2400 baud IR link and a
1200/2400/9600 baud RS232 port. The 48S, 48SX and 48G have
32Kb of RAM, almost none of which is used by the operating
system. The 48GX has 128Kb of RAM. With an entry price of
~100$ US, I feel that the HP-48 series would be a good choice
for a smart token. Possible uses are as digital cash wallets
and authentication tokens, not the mention simple encrypted
dumb terminals.
Installation:
If you have a serial cable, download the code below to
your HP and call it 'RC4'. This will create a directory
called 'RC4' with four programs in it. If you don't have a
cable you can type the whole thing in; it's not too large.
Store it as 'RC4' and again it will create a directory. Remember
not to type the "%%HP: T(3)A(D)F(.);" -- it's only needed for
a serial download.
Instructions:
These instructions assume that you are familiar with
stream-ciphers in general. If you are not, you might want to
get _Applied Cryptography_ by Bruce Schneier from your library
or book store.
Bit streams are represented as one dimensional arrays of
real numbers between 0 and 255. Yes, that's right, this
cipher uses floating-point! In User-RPL it's the fastest way.
To convert between strings and arrays use the commands S2A and
A2S.
S2A "String" -> [Array]
A2S [Array] -> "String"
To setup a key, use the SK command. It takes a
bitstream representing the keytext and returns the key
context. They keytext can be up to 256 bytes long.
Additional bytes will not be used. The key context is another
bitstream with 256 values in it. Because of time/memory
tradeoffs, a key context takes 2082 bytes of RAM to store. If
memory is tight, use A2S to compress the key context to a
string.
SK [Key text] -> [Key context]
To encrypt something use the RC4 command. The first
argument is the key context, the second is the plaintext or
ciphertext, both in bitstream form. It returns the updated
key context and the ciphertext or plaintext.
RC4 [Key context], [Plaintext] ->
[New key context], [Ciphertext]
or
RC4 [Key context], [Ciphertext] ->
[New key context], [Plaintext]
Enjoy
The Cunning Artificers
- -- CUT HERE --
%%HP: T(3)A(D)F(.);
DIR
SK
\<< DTAG OBJ\-> OBJ\-> DROP 0 255
FOR N N NEXT 259 258
PICK + 0 259 4 FOR N OVER
PICK N PICK + + 256 MOD DUP 255 - NEG N
4 - DUP2 IF \=/
THEN DUP2
IF >
THEN SWAP
END
DUP2 6 + ROLL SWAP 6 +
ROLL SWAP 4 ROLL 5 + ROLLD SWAP 3 +
ROLLD
ELSE
DROP2
END SWAP 1 - DUP
IF 260 <
THEN
DROP 258 PICK 259 +
END SWAP -1
STEP DROP2 0
0 258 \->ARRY OVER 2
+ ROLLD DROPN "Key"
\->TAG
\>>
RC4
\<< DTAG DUP SIZE OBJ\-> DROP 3 PICK
258 GET 4 PICK 257 GET 1 + 1 4 ROLL
FOR N 256 MOD 1 + DUP 5 PICK SWAP
GET 3 ROLL + 256 MOD 1 + DUP 5 ROLL
SWAP 4 PICK CSWP DUP DUP 5 PICK GET
OVER 5 PICK GET + 256 MOD 1 + GET 5
ROLL DUP N GET R\->B 3 ROLL R\->B XOR B\->R
N SWAP PUT 4 ROLL 4 ROLL 1 - SWAP
NEXT 4 ROLL 257 3 ROLL 1 - PUT
258 3 ROLL PUT "Updated key" \->TAG
SWAP "Result" \->TAG
\>>
S2A
\<< DUP SIZE
\<< \-> LEN
\<< 1 LEN
START DUP NUM SWAP TAIL
NEXT DROP LEN
\>>
\>> EVAL 1
\->LIST \->ARRY
\>>
A2S
\<< DTAG OBJ\-> OBJ\-> DROP "" SWAP 1
SWAP START SWAP CHR SWAP + NEXT
\>>
END
- -- CUT HERE --
- -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzEAEf4AAAEEAMONoLHj5CwKvaM6ch9GOcUjgoVS5sjXa4TzD2ohhtHFYR9l
QzNj0vNASBQKE/Mk9Flqg+dtitS7S7B0qZQ+mQmMT73yniun596jt1NCJ5sLBKrM
jDvYK3wGbycVX43RBiR3iwJZGq5blfWqNRE7kFdTxgu+bCdtLOFNVew9oBf9AAUR
tBZUaGUgQ3VubmluZyBBcnRpZmljZXJz
=pf3Y
- -----END PGP PUBLIC KEY BLOCK-----
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBMQRCWuFNVew9oBf9AQEPJgP/QzwxGIWU0sf+a8Vzj2tXtMqRhRQjG4Qp
Pcrwr76WhM/2KnHGNAdC3lKwyEK17cu32zbmPePhOvtdUNyV3L1KZlBioURK5Kxu
ZspnOLCmlKo8lbOa5mJl2bmV55W49B96ua+yxst1XaOzhfYDN/KjZsztGRnEbQx9
VovMpLXooLo=
=4pzv
-----END PGP SIGNATURE-----