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

Published on 12 May 2024 09:40 PM

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

Source code in the tuscript programming language

$$ MODE TUSCRIPT
text="THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
PRINT "text orginal    ",text

abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ",key=3,caesarskey=key+1
secretbeg=EXTRACT (abc,#caesarskey,0)
secretend=EXTRACT (abc,0,#caesarskey)
secretabc=CONCAT (secretbeg,secretend)

abc=STRINGS (abc,":
abc=SPLIT (abc),         secretabc=SPLIT (secretabc)
abc2secret=JOIN(abc," ",secretabc),secret2abc=JOIN(secretabc," ",abc)

BUILD X_TABLE abc2secret=*
DATA  {abc2secret}

BUILD X_TABLE secret2abc=*
DATA  {secret2abc}

ENCODED = EXCHANGE (text,abc2secret)
PRINT "text encoded    ",encoded

DECODED = EXCHANGE (encoded,secret2abc)
PRINT "encoded decoded ",decoded

  

You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the Phix programming language
You may also check:How to resolve the algorithm Empty directory step by step in the Ada programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Factor programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Perl programming language
You may also check:How to resolve the algorithm Test a function step by step in the Mathematica/Wolfram Language programming language