Post Reply 
(38G) Hill's Encryption System
10-01-2015, 10:16 AM (This post was last modified: 06-15-2017 01:56 PM by Gene.)
Post: #1
(38G) Hill's Encryption System
The following four programmes implement Hill's Cypher system for the HP 38G.

HILLSET stores the parameters, encyphering & decyphering matrices & additional cypher vector, in M9, M0 & M8.
The programme asks for an encyphering modulus, for English perhaps 26, & size of cyphering matrices & vector, conveniently 4 to fit on the screen.

ENCY encyphers the conformable matrix M1 & stores the result in M1.

DECY decyphers the conformable matrix M1 & stores the result in M1.

M1ADDV8 adds/subtracts the comformable vector M8 to the rows of M1.

For info on Hill's system see:

https://en.wikipedia.org/wiki/Hill_cipher

HILLSET
Code:

INPUT C;"Hill Cryptosystem"; "Modulus";" Cypher Modulus ► C";26:
INPUT S;"Hill Cryptosystem"; "Size";" Size of Cypher Matrix ► S";4:
IDENMAT(S)►M0:
FOR I=1 TO S STEP 1;
FOR J=1 TO S STEP 1;
IF I==J
THEN
IF RANDOM>.5
THEN
-1►M0(I,I):
END:
S►J:
ELSE
INT(C*(RANDOM))►M0(I,J):
END:
END:
END: 
M0:
Ans*TRN(Ans):
MAKEMAT(Ans(I,J)MOD C,S,S
)►M9:
M0^-1:
MAKEMAT(
ROUND(Ans(I,J),0),S,S):
TRN(Ans)*Ans:
MAKEMAT(Ans(I,J)MOD C,S,S
)►M0:
MAKEMAT(INT(C*RANDOM),1,S)►M8:
ENCY
Code:

SIZE(M1):
Ans(1)►T:
SIZE(M9):
Ans(1)►S:
M1*M9:
MAKEMAT(Ans(I,J)MOD C,T,S
)►M1:
1:
RUN M1ADDV8:
DECY
Code:

-1:
RUN M1ADDV8:
SIZE(M1):
Ans(1)►T:
SIZE(M0):
Ans(1)►S:
M1*M0:
MAKEMAT(Ans(I,J)MOD C,T,S
)►M1:
M1ADDV8
Code:

Ans►V:
SIZE(M1):
MAKEMAT((M1(I,J)+V*M8(1,J))MOD C,Ans(1),S)►M1:
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(38G) Hill's Encryption System - Gerald H - 10-01-2015 10:16 AM



User(s) browsing this thread: 1 Guest(s)