How to resolve the algorithm Caesar cipher step by step in the Run BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Caesar cipher step by step in the Run BASIC 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 Run BASIC programming language

Source code in the run programming language

input "Gimme a ofset:";ofst       ' set any offset you like

a$ = "Pack my box with five dozen liquor jugs"
print " Original: ";a$
a$ = cipher$(a$,ofst)
print "Encrypted: ";a$
print "Decrypted: ";cipher$(a$,ofst+6)

FUNCTION cipher$(a$,ofst)
for i = 1 to len(a$)
  aa$   = mid$(a$,i,1)
  code$ = " "
  if aa$ <> " " then
    ua$   = upper$(aa$)
    a     = asc(ua$) - 64
    code$ = chr$((((a mod 26) + ofst) mod 26) + 65)
    if ua$ <> aa$ then code$ = lower$(code$)
  end if
  cipher$ = cipher$;code$
next i
END FUNCTION

  

You may also check:How to resolve the algorithm Get system command output step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Topic variable step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Ternary logic step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Soloway's recurring rainfall step by step in the C# programming language
You may also check:How to resolve the algorithm User input/Text step by step in the ALGOL 68 programming language