

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


*        Caesar cypher             04/01/2019
CAESARO  PROLOG
         XPRNT  PHRASE,L'PHRASE    print phrase
         LH     R3,OFFSET          offset
         BAL    R14,CYPHER         call cypher
         LNR    R3,R3              -offset
         BAL    R14,CYPHER         call cypher
         EPILOG         
CYPHER   LA     R4,REF(R3)         @ref+offset
         MVC    A,0(R4)            for A to I
         MVC    J,9(R4)            for J to R
         MVC    S,18(R4)           for S to Z
         TR     PHRASE,TABLE       translate
         XPRNT  PHRASE,L'PHRASE    print phrase         
         BR     R14                return         
OFFSET   DC     H'22'              between -25 and +25
PHRASE   DC     CL37'THE FIVE BOXING WIZARDS JUMP QUICKLY'
         DC     CL26'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
REF      DC     CL26'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
         DC     CL26'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
TABLE    DC     CL256' '           translate table for TR
         ORG    TABLE+C'A'
A        DS     CL9
         ORG    TABLE+C'J'
J        DS     CL9
         ORG    TABLE+C'S'
S        DS     CL8
         ORG
         YREGS                        
         END    CAESARO