Porta27

Display

Overview
Program PORTA 27 implements an encryption variation by Giambattista della Porta, known as polyalphabetic cipher, so called bigraphic substitution. Porta published De Furtivis Literarum Notis in 1563. This program is written for the HP-41CX as minimisation of the program in chapter 7 of the book: Kryptologie (HP-41 C/CV): Chiffrierung, Textverschlüsselung, Datenschutz, Morsealphabet; Alt, Helmut; Schumny, Harald [Hrsg.], Braunschweig [u.a.]. Vieweg. 1983. Vieweg-Programm-bibliothek Taschenrechner Band 7. ISBN 3-528-04256-7.

Formulae
Coding according to Porta is done on looking up the value of two consecutive characters in a the table on the next page. For example the word “PO” can be coded as 420. If a word has an odd number of characters, a space is appended for completion of the Porta coding. The table lookup can be computed following below algorithms:

FORWARD Taking the two consecutive characters in a word C1 and C2, the Porta code cp can be determined as follows:
cp = 27.(C1 – 1) + C2 C1, C2 are A..Z,space
cp = 27.C1 + C2 – 1819 Subsituting Ci = Ci + (65-1), where 65 is char value of A
BACKWARD Taking the Porta code cp, the two consecutive characters in a word C1 and C2 can be determined as follows:
C1 = INT(0,99 + cp/27)
C2 = INT(0,99 + 27.FRC(cp/27))
cp is 1..729

The lookup table shows a base of 27. More bases are possible if more characters need to be encrypted. An example of coding the word HOOXIES is given which translates into a series of cp values: 204, 402, 221 and 513.

Encryption Table
Cross first character in the left column with the second character in the top row. The character sequence is the encrypted code.
For example, the word HOOXIES can be coded as follows:
1. “HO”, in table is: 204
2. “OX”, in table is: 402
3. “IE”, in table is: 221
4. “S “, in table is: 513

Example (1)
Please note my default FIX 5 setting in de examples below for the codes.


Keystrokes: Display: Comments:
[XEQ][ALPHA] P27 [ALPHA] TXT=? - Enter Ci values, e.g. PORTAS CODING ON HOOXIES
PORTA CODING ON HOOXIES [R/S] 420,00000 - First value cp
[R/S] 479,00000 - Second value cp
[R/S] 27,00000 - Third value cp
[R/S] 69,00000 - Fourth value cp
[R/S] 90,00000 - Fifth value cp
[R/S] 358,00000 - Sixth value cp
[R/S] 513,00000 - Seventh value cp
[R/S] 392,00000 - Eighth value cp
[R/S] 710,00000 - Nineth value cp
[R/S] 393,00000 - Tenth value cp
[R/S] 630,00000 - Eleventh value cp
[R/S] 127,00000 - Twelfth value cp
[R/S] OK - Completed: 420-479-27-69-90-358-513-392-710-393-630-127
[R/S] TXT=? - Enter new Ci values, e.g. HP
HP [R/S] 205,00000 - Value cp
[R/S] OK - Completed: 205
[R/S] TXT=? - Enter other Ci values

Example (2)
Below example decrypts a numerical sequence back to a text:


Keystrokes: Display: Comments:
[XEQ][ALPHA] P27-1 [ALPHA] CODE=? - Enter first cp value, e.g. 204
204 [R/S] HO - Enter second cp value, e.g. 402
402 [R/S] HOOX - Enter third cp value, e.g. 402
221 [R/S] HOOXIE - Enter fourth cp value, e.g. 402
513 [R/S] HOOXIES - Stop entering new values and press R/S to continue
[R/S] HOOXIES . - Completed indicated with dot at the end
[R/S] CODE=? - Start with new cp value

Program Listing

LINE  KEYS                LINE  KEYS              LINE  KEYS              LINE  KEYS

01 LBL'P27' 20 RCL 02 01 LBL'P27-1' 20 GTO 00
02 LBL 03 21 + 02 'CODE=?' 21 LBL 03
03 'TXT=?' 22 1819 03 AVIEW 22 ,99
04 AON 23 - 04 CLA 23 +
05 PROMPT 24 STOP 05 LBL 00 24 INT
06 AOFF 25 DSE 00 06 CF 22 25 X=0?
07 ALENG 26 GTO 00 07 STOP 26 '» '
08 STO 00 27 'OK' 08 FC? 22 27 X=0?
09 2 28 PROMPT 09 GTO 02 28 RTN
10 MOD 29 GTO 03 10 27 29 64
11 ST+00 30 LBL 02 11 / 30 +
12 LASTX 31 32 12 STO 01 31 XTOA
13 ST/00 32 ATOX 13 XEQ 03 32 RTN
14 LBL 00 33 X>Y? 14 RCL 01 33 LBL 02
15 XEQ 02 34 RTN 15 FRC 34 '».'
16 27 35 91 16 27 35 AVIEW
17 * 36 END 17 * 36 END
18 STO 02 18 XEQ 03
19 XEQ 02 68 bytes 19 AVIEW 70 bytes

Program P27 makes use of an optimised (forward) algorithm that includes the character values of alphas A..Z (65..90). However, the space value (32) does not fit so nicely in this sequence, the formulae is non-linear. In LBL 02 this is intercepted by checking against 32. If the ATOX value exceeds 32, it can proceed according to the forward algortihm, otherwise it substitutes the value 91 representing the character value of a space in the optimised (forward) algorithm.

Program P27-1 has to cope with the same non-linear problem of the space. In LBL 03 it checks whether the calculated character value is zero. This happens for character 27 (space) and results in cp/27 getting very close to zero. The program checks whether X=0? and appends a space to the text string, otherwise it converts XTOA (atter first adding 64 to any of the possible values 1..26).

Registers
R00 Number of required lookups: length of the text string divided by 2
R01 cp divided by 27

Flags
22 Check keyboard input

© 2009 by Auke Hoekstra

Leave a Reply