(42S) Hill's Encryption System - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (42S) Hill's Encryption System (/thread-2485.html) |
(42S) Hill's Encryption System - Gerald H - 11-24-2014 07:39 PM (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. RE: (42S) Hill's Encryption System - Gerald H - 07-10-2022 09:33 AM Error in programme ENCY corrected - Did anybody in the meantime notice? RE: (42S) Hill's Encryption System - Thomas Klemm - 07-11-2022 03:22 PM 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 } Not sure though if it is useful here since the Z register is overwritten. RE: (42S) Hill's Encryption System - Gerald H - 07-12-2022 04:54 AM 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 } |