hp41programs

Cryptography

Cryptography for the HP-41


Overview
 

-"CYPHER" allows to code and decode a text that has been stored into data registers by groups of 1 to 6 characters.
-The key is simply a random seed. The same one is used for coding and decoding.
-X-Functions module is required.
-A routine is also listed to store alpha strings into contiguous registers.
 

Program Listing
 

Data Registers:            R00 to R03: temp                        ( Registers Rbb thru Ree are to be initialized before executing "CYPHER" )

                                   •  Rbb  •  Rbb+1  ...............  •  Ree = the message     bbb > 003     ( R03 = bbb.eee )

     >>> When the program stops, the coded message has replaced the original  ( or vice versa )

Flag:   CF 01 to code a message
            SF 01 to decode a message

Subroutines: /
 
 

01  LBL "CYPHER"
02  STO 00
03  X<>Y
04  STO 01
05  STO 03
06  255
07  STO 02
08  LBL 01
09  CLA
10  ARCL IND 01  
11  ALENG
12  LBL 02
13  ATOX
14  RCL 00
15  R-D
16  FRC
17  STO 00
18  RCL 02             
19  *
20  INT
21  FS? 01
22  CHS
23  +
24  RCL 02
25  MOD
26  X=0?
27  X<> L
28  XTOA
29  X<>Y
30  DSE X
31  GTO 02
32  ASTO IND 01  
33  ISG 01
34  GTO 01
35  RCL 03             
36  CLA
37  END

 
   ( 61 bytes )
 
 

      STACK        INPUTS     OUTPUTS
           Y        bbb.eee            /
           X             r        bbb.eee

  where  bbb.eee  is the comtrol number of the message registers  ( bbb > 003 )
    and         r        is the key

Example:

-You have stored

          "MYNAME"     in register   R11
           "ISBOND"       in register   R12
           "JAMES "         in register   R13
           "BOND"           in register   R14

-If your key is  r = 1  ( a more sophisticated key is recommended... )

   CF 01   11.014   ENTER^
                     1      XEQ "CYPHER"  >>>>  11.014                 --- Execution time = 17s ---

-The coded message is now in registers R11 thru R14 ( many of the characters are displayed as starbursts )

-To decode this message:

   SF 01   11.014   ENTER^
                    1           R/S      >>>>   11.014    and the original alpha strings are in R11 to R14 again.
 

Notes:

-For a 600 character message ( stored in 100 registers ), execution time = 7mn40s.
-We must avoid the null character since it disappears when shifted into the leftmost position.
-Otherwise, all the characters with an ASCII code from 1 to 255 are allowed.
-"CYPHER" uses the random number generator  R-D  FRC , so choose r so that  180*r/PI is not an integer.
-Using this program several times with several keys could produce an almost unbreakable encryption.
 

Storing Alpha Strings
 

-Line 22 is one space.
-Lile 24 is  append  ?
 
 

01  LBL "AIN"    
02  ENTER^
03  AON
04  1
05  ST- Y
06  GTO 02
07  LBL 01
08  ISG Z
09  CLX
10  ASTO IND Z
11  ASHF
12  CLX
13  ALENG
14  X#0?
15  GTO 01
16  SIGN
17  +
18  LBL 02
19  RCLFLAG   
20  FIX 0
21  CF 29
22  " "
23  ARCL Y
24  "~?"
25  STOFLAG   
26  STOP
27  FS?C 23
28  GTO 01
29  AOFF
30  RDN
31  CLX
32   E3
33  /
34  +
35  CLA            
36  END

 
   ( 61 bytes )
 
 

      STACK        INPUT      OUTPUT
           X           bbb       bbb.eee

 
Example:   You want to store the confidential message:   "THE GARDEN PEAS ARE SIMMERING IN THE SAUCEPAN"   into registers R00 , R01 , .....

               0  XEQ "AIN"                           the HP-41 displays  1?   ( the alpha keyboard is activated - line 03 )  key in:
 "THE GARDEN PEAS ARE SIMM"      you hear a TONE since there are now 24 characters in the alpha "register".
                  press  R/S                               the HP-41 displays  2?   key in:
 "ERING IN THE SAUCEPAN"
                  press R/S                                the HP-41 displays  3?
       simply press R/S without any entry     the HP-41  returns the control number  0.007

-Your message has been stored into registers R00 thru R07