Page 1 of 1

Encryption and decryption of text

Posted: Sat Aug 28, 2021 10:46 am
by rawi
This program allows to encrypt and decrypt messages.

Application:
At the beginning you are asked for the starting value of the random number generator: SEED?
Take any number between 0 and 1.
The same number has to be used for encryption and decryption.
Then you are asked whether you want to encrypt or to decrypt ENC=1 DEC=2?
Put in 1 for encryption, 2 for decryption.
Then you are asked for a character. You can use any of the following 44 characters:
[Space] * + , - . / : 0 to 9 A to Z.
Only characters are used that can be easily accessed by the keyboard.
After putting in the character and pressing R/S you are shown the encrypted (or decrypted) character and you can input the next character and press R/S

Example: We want to encrypt and decrypt the following phrase: THE CALCULATOR FORUM
XEQ alpha CRYP alpha
-> SEED? We take Pi – 3: PI 3 – R/S
-> ENC = 1 DEC = 2? We want to encrypt, therefore: 1 R/S
-> CHAR? -> T R/S -> K (K is the encryption for T at that place). Next letter overwrites the encryption.
-> H R/S -> N -> E R/S -> / -> (Space) R/S -> D …

The whole phrase encrypted as follows:
KN/DFC/03J1*.71T6T2R

Note that the same character is transformed to different encrypted characters like the first A from Calculator to C and the second to 1. Note that as well the same character in the encrypted phrase can be different characters in the not encrypted phrase like the first “/” stands for E and the second for L. Furthermore space is coded as well so that length of words cannot be used to decipher.

Decryption:
XEQ alpha CRYP alpha
-> SEED? To decrypt we have to take the same number: PI 3 – R/S
-> ENC = 1 DEC = 2? We want to decrypt, therefore:2 R/S
-> CHAR? We type K (the first letter of the encrypted phrase) R/S -> T (the first letter of the not encrypted phrase) -> N R/S -> H -> / R/S -> E D R/S -> (space) …

Note: If no character is shown this stands for space.
Method:
For every character a random number generator is used to encrypt it. So the meaning of a character is position sensitive.
The random number generator is in lines 28-32. It has the form: r(n) = Frac(9821*r(n-1)+0.211327).
It was taken from the HP Standard Programs Book for the HP 34C.

Enjoy!

Code: Select all

01 LBL alpha CRYP alpha
02 alpha SEED? alpha
03 PROMPT
04 STO 00
05 alpha ENC=1 DEC=2? alpha
06 PROMPT
07 STO 01
08 AON
09 alpha CHAR? alpha
10 PROMPT
11 LBL 00
12 ATOX
13 31
14 -
15 1
16 X<>Y
17 X<=Y?
18 GTO 03
19 9
20 -
21 18
22 X<>Y
23 X<=Y?
24 GTO 03
25 6
26 -
27 LBL 03
28 RCL 00
29 9821
30 *
31 .211327
32 +
33 FRC
34 STO 00
35 44
36 *
37 1
38 +
39 INT
40 XEQ IND 01
41 31
42 +
43 32
44 X<>Y
45 X<=Y?
46 GTO 04
47 9
48 +
49 58
50 X<>Y
51 X<=Y?
52 GTO 04
53 6
54 +
55 LBL04
56 XTOA
57 STOP
58 GTO 00
59 LBL 01
60 +
61 44
62 X<>Y
63 X<=Y?
64 RTN
65 X<>Y
66 -
67 RTN
68 LBL 02
69 -
70 X>0?
71 RTN
72 44
73 +
74 RTN
75 END

Re: Encryption and decryption of text

Posted: Sat Oct 09, 2021 5:26 pm
by rawi
Deleted

Re: Encryption and decryption of text

Posted: Sat Oct 09, 2021 5:34 pm
by rawi
New version that allows do encrypt and decrypt not just one character at a time but up to 24.

Application:

At the beginning you are asked for the starting value of the random number generator: SEED?
Take any number between 0 and 1.
The same number has to be used for encryption and decryption.
Then you are asked whether you want to encrypt or to decrypt ENC=1 DEC=2?
Put in 1 for encryption, 2 for decryption.
Then you are asked for a text. Put in the first part of your text. Maximum length of a part of text is 24 characters including spaces. You can use any of the following 44 characters:
Space * + , - . / : 0 to 9 A to Z
Then you are shown the encrypted or decrypted part of your text and you are asked to put in the next part of your text.
Example: We want to encrypt and decrypt the following phrase: I LIKE THE CALCULATOR FORUM
Encryption:
XEQ alpha CRPT alpha
-> SEED? We take Pi – 3: PI 3 – R/S
-> ENC = 1 DEC = 2? We want to encrypt, therefore: 1 R/S
-> TEXT? -> We type: I LIKE THE (first part of text) R/S -> :/6,NGDGXC (encrypted text for first part). R/S -> TEXT? -> We type: CALCULATOR FORUM (second part of text) R/S -> 3I+Z+ZZV,W+GPXZZ (encrypted text of second part of text).
Decryption:
XEQ alpha CRPT alpha
-> SEED? We have to use the same seed to come to results, so we take again Pi – 3: PI 3 – R/S
-> ENC = 1 DEC = 2? We want to decrypt, therefore:2 R/S
-> TEXT? We type: :/6,NGDGXC (the first part of the text we want to decode) R/S -> I LIKE THE (first part of text decrypted) -> R/S -> TEXT? We type: 3I+Z+ZZV,W+GPXZZ (second part of text) R/S -> CALCULATOR FORUM (second part of text decrypted).

Method:
For every character a random number generator is used to encrypt it. So the meaning of a character is position sensitive.
The random number generator is in lines 28-32. It has the form: r(n) = Frac(9821*r(n-1)+0.211327).
It was taken from the HP Standard Programs Book for the HP 34C.

Use of Registers: Registers 00 – 28 used
01 LBL TCRPT
02 TSEED?
03 PROMPT
04 STO 00
05 TENC=1 DEC=2?
06 PROMPT
07 STO 01
08 LBL 07
09 4
10 STO 02
11 AON
12 TTEXT?
13 PROMPT
14 LBL 00
15 ATOX
16 X=0?
17 GTO 05
18 31
19 -
20 1
21 X<>Y
22 X<=Y?
23 GTO 03
24 9
25 -
26 18
27 X<>Y
28 X<=Y?
29 GTO 03
30 6
31 -
32 LBL 03
33 RCL 00
34 9821
35 *
36 .211327
37 +
38 FRC
39 STO 00
40 44
41 *
42 1
43 +
44 INT
45 XEQ IND 01
46 31
47 +
48 32
49 X<>Y
50 X<=Y?
51 GTO 04
52 9
53 +
54 58
55 X<>Y
56 X<=Y?
57 GTO 04
58 6
59 +
60 LBL04
61 STO IND 02
62 1
63 ST+ 02
64 GTO 00
65 LBL 05
66 RCL 02
67 STO 03
68 4
69 STO 02
70 LBL 06
71 RCL IND 02
72 XTOA
73 1
74 ST+ 02
75 RCL 02
76 RCL 03
77 X>Y?
78 GTO 06
79 AON
80 STOP
81 GTO 07
82 LBL 01
83 +
84 44
85 X<>Y
86 X<=Y?
87 RTN
88 X<>Y
89 -
90 RTN
91 LBL 02
92 -
93 X>0?
94 RTN
95 44
96 +
97 RTN
98 END