

Task

Implement a Caesar cipher, both encoding and decoding. 

The key is an integer from 1 to 25.

This cipher rotates (either towards left or right) the letters of the alphabet (A to Z).

The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A).

So key 2 encrypts "HI" to "JK", but key 20 encrypts "HI" to "BC".

This simple "mono-alphabetic substitution cipher" provides almost no security, because an attacker who has the encoded message can either use frequency analysis to guess the key, or just try all 25 keys.

Caesar cipher is identical to Vigenère cipher with a key of length 1. 

Also, Rot-13 is identical to Caesar cipher with key 13.



Related tasks

 Rot-13
 Substitution Cipher
 Vigenère Cipher/Cryptanalysis


10 LET t$="PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS"
20 PRINT t$''
30 LET key=RND*25+1
40 LET k=key: GO SUB 1000: PRINT t$''
50 LET k=26-key: GO SUB 1000: PRINT t$
60 STOP 
1000 FOR i=1 TO LEN t$
1010 LET c= CODE t$(i)
1020 IF c<65 OR c>90 THEN GO TO 1050
1030 LET c=c+k: IF c>90 THEN LET c=c-90+64
1040 LET t$(i)=CHR$ c
1050 NEXT i
1060 RETURN 
 