How to resolve the algorithm Vigenère cipher step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Vigenère cipher step by step in the REXX programming language
Table of Contents
Problem Statement
Implement a Vigenère cypher, both encryption and decryption. The program should handle keys and text of unequal length, and should capitalize everything and discard non-alphabetic characters. (If your program handles non-alphabetic characters in another way, make a note of it.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Vigenère cipher step by step in the REXX programming language
Source code in the rexx programming language
/*REXX program encrypts (and displays) uppercased text using the Vigenère cypher.*/
@.1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
L=length(@.1)
do j=2 to L; jm=j-1; q=@.jm
@.j=substr(q, 2, L - 1)left(q, 1)
end /*j*/
cypher = space('WHOOP DE DOO NO BIG DEAL HERE OR THERE', 0)
oMsg = 'People solve problems by trial and error; judgement helps pick the trial.'
oMsgU = oMsg; upper oMsgU
cypher_= copies(cypher, length(oMsg) % length(cypher) )
say ' original text =' oMsg
xMsg= Ncypher(oMsgU); say ' cyphered text =' xMsg
bMsg= Dcypher(xMsg) ; say 're-cyphered text =' bMsg
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
Ncypher: parse arg x; nMsg=; #=1 /*unsupported char? ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
do i=1 for length(x); j=pos(substr(x,i,1), @.1); if j==0 then iterate
nMsg=nMsg || substr(@.j, pos( substr( cypher_, #, 1), @.1), 1); #=#+1
end /*j*/
return nMsg
/*──────────────────────────────────────────────────────────────────────────────────────*/
Dcypher: parse arg x; dMsg=
do i=1 for length(x); j=pos(substr(cypher_, i, 1), @.1)
dMsg=dMsg || substr(@.1, pos( substr(x, i, 1), @.j), 1 )
end /*j*/
return dMsg
/*REXX program encrypts (and displays) most text using the Vigenère cypher. */
@abc= 'abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
@.1 = @abcU || @abc'0123456789~`!@#$%^&*()_-+={}|[]\:;<>?,./" '''
L=length(@.1)
do j=2 to length(@.1); jm=j - 1; q=@.jm
@.j=substr(q, 2, L - 1)left(q, 1)
end /*j*/
cypher = space('WHOOP DE DOO NO BIG DEAL HERE OR THERE', 0)
oMsg = 'Making things easy is just knowing the shortcuts. --- Gerard J. Schildberger'
cypher_= copies(cypher, length(oMsg) % length(cypher) )
say ' original text =' oMsg
xMsg= Ncypher(oMsg); say ' cyphered text =' xMsg
bMsg= Dcypher(xMsg); say 're-cyphered text =' bMsg
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
Ncypher: parse arg x; nMsg=; #=1 /*unsupported char? ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
do i=1 for length(x); j=pos(substr(x,i,1), @.1); if j==0 then iterate
nMsg=nMsg || substr(@.j, pos( substr( cypher_, #, 1), @.1), 1); #=# + 1
end /*j*/
return nMsg
/*──────────────────────────────────────────────────────────────────────────────────────*/
Dcypher: parse arg x; dMsg=
do i=1 for length(x); j=pos(substr(cypher_, i, 1), @.1)
dMsg=dMsg || substr(@.1, pos( substr(x, i, 1), @.j), 1 )
end /*j*/
return dMsg
You may also check:How to resolve the algorithm Sierpinski carpet step by step in the Brainf*** programming language
You may also check:How to resolve the algorithm Sum and product puzzle step by step in the Go programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the Erlang programming language
You may also check:How to resolve the algorithm Use another language to call a function step by step in the Java programming language