How to resolve the algorithm Caesar cipher step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Caesar cipher step by step in the 11l programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Caesar cipher step by step in the 11l programming language

Source code in the 11l programming language

F caesar(string, =key, decode = 0B)
   I decode
      key = 26 - key

   V r = ‘ ’ * string.len
   L(c) string
      r[L.index] = S c
                      ‘a’..‘z’
                         Char(code' (c.code - ‘a’.code + key) % 26 + ‘a’.code)
                      ‘A’..‘Z’
                         Char(code' (c.code - ‘A’.code + key) % 26 + ‘A’.code)
                      E
                         c
   R r

V msg = ‘The quick brown fox jumped over the lazy dogs’
print(msg)
V enc = caesar(msg, 11)
print(enc)
print(caesar(enc, 11, decode' 1B))

  

You may also check:How to resolve the algorithm Repeat a string step by step in the Perl programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the HicEst programming language
You may also check:How to resolve the algorithm Chaos game step by step in the Perl programming language
You may also check:How to resolve the algorithm Bitmap step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the UnixPipes programming language