Post Reply 
(42S) Hill's Encryption System
11-24-2014, 07:39 PM (This post was last modified: 07-10-2022 09:41 AM by Gerald H.)
Post: #1
(42S) Hill's Encryption System
(Edit 2022-07-10: Last programme, ENCY, old line 19 removed & size of programme corrected.)

Hill’s ciphering algorithm can be accomplished on the HP 42S using the following programmes.

To use:

1. Actuate programme HILL to set parameters.
2. ENCY encodes the alpha register, returning the coded message to the alpha register.
3. DECY decodes the alpha register, returning the clear message to the alpha register.


0. { 33-Byte Prgm }
1. LBL “R10”
2. RAN
3. SF 25
4. RCL “RMAX”
5. FC?C 25
6. 10
7. *
8. IP
9. RAN
10. 0.5
11. –
12. SIGN
13. *
14. END

Produces one random integer element of the ciphering matrices.

0. { 43-Byte Prgm }
1. LBL “LTRI”
2. ENTER
3. NEWMAT
4. EDIT
5. LBL 00
6. RCLIJ
7. X=Y?
8. GTO 01
9. XEQ “R10”
10. →
11. GTO 00
12. LBL 01
13. SIGN
14. STOEL
15. STOIJ
16. I+
17. FC? 76
18. GTO 00
19. CLX
20. EXITALL
21. END

Forms a lower triangular square matrix for integer input
Eg 3 LTRI returns a 3*3 LT matrix.

0. { 22-Byte Prgm }
1. LBL “MMOD”
2. EDIT
3. LBL 00
4. RCL ST Y
5. MOD
6. →
7. FC? 77
8. GTO 00
9. EXITALL
10. END

Makes the matrix in X-register modulo the integer in the Y-register
Eg 7 matrix MMOD returns the matrix modulo 7.

0. { 34-Byte Prgm }
1. LBL “A→M”
2. ALENG
3. RCL/ ST Y
4. ENTER
5. FP
6. X>0?
7. SIGN
8. +
9. X<>Y
10. NEWMAT
11. EDIT
12. LBL 00
13. R↓
14. ATOX
15. →
16. FC? 77
17. GTO 00
18. EXITALL
19. END

Converts the alpha-register contents to a matrix of integers of column dimension the X-register
Eg 3 A→M returns a 3-column matrix.

0. { 95-Byte Prgm }
1. LBL “HILL”
2. INPUT “RMAX”
3. INPUT “SHIFT”
4. INPUT “CYMOD”
5. INPUT “MSIZE”
6. XEQ “LTRI”
7. ENTER
8. ENTER
9. TRANS
10. *
11. RCL “CYMOD”
12. X<>Y
13. XEQ “MMOD”
14. STO “INMAT”
15. R↓
16. X<>Y
17. FIX 00
18. INVRT
19. RND
20. ALL
21. ENTER
22. TRANS
23. X<>Y
24. *
25. XEQ “MMOD”
26. STO “OUTMAT”
27. END

Asks for the coding parameters.
Eg For capitals in to capitals out:

Alpha to alpha: SHIFT 65
CYMOD 26

For any character in to any character out:

All to all: SHIFT 0
CYMOD 256


0. { 78-Byte Prgm }
1. LBL “ENCY”
2. RCL “INMAT”
3. GTO 00
4. LBL “DECY”
5. RCL “OUTMAT”
6. LBL 00
7. ENTER
8. DIM?
9. X<>Y
10. R↓
11. XEQ “A→M”
12. X<>Y
13. *
14. RCL+ “SHIFT”
15. RCL “CYMOD”
16. X<>Y
17. XEQ “MMOD”
18. RCL+ “SHIFT”
19. CLA
20. XTOA
21. AVIEW
22. END


ENCY encodes the alpha-register & DECY decodes the alpha-register.
Find all posts by this user
Quote this message in a reply
07-10-2022, 09:33 AM
Post: #2
RE: (42S) Hill's Encryption System
Error in programme ENCY corrected - Did anybody in the meantime notice?
Find all posts by this user
Quote this message in a reply
07-11-2022, 03:22 PM
Post: #3
RE: (42S) Hill's Encryption System
When I took a closer look at the "MMOD" program I wondered why you wouldn't just use the MOD operation.
But it gives an Invalid Type error message.

However division and integer part work on matrices.
So you could use the following instead:
Code:
00 { 16-Byte Prgm }
01▸LBL "MMOD"
02 STO ST Z
03 RCL÷ ST Y
04 IP
05 ×
06 -
07 END

Not sure though if it is useful here since the Z register is overwritten.
Find all posts by this user
Quote this message in a reply
07-12-2022, 04:54 AM
Post: #4
RE: (42S) Hill's Encryption System
Thank you Thomas for your suggestion.

While your programme gives correct results the returned numbers respect the sign of elements of the matrix, whereas the built-in function MOD returns positive answers for a positive base, which values the cyphering processes depend on.

Consequently not utile for this set of programmes.

I prefer the programme below, it may avoid problems with non-integer outputs of your programme - however, still respects sign of input:

Code:
00 { 20-Byte Prgm }
01▸LBL "MMOD"
02 FIX 00
03 RCL÷ ST Y
04 FP
05 RCL* ST Y
06 RND
07 ALL
08 END
Find all posts by this user
Quote this message in a reply
Post Reply 




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