2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,22 +1,22 @@
|
|||
/*REXX pgm: Caesar cypher: Latin alphabet only, no punctuation or blanks*/
|
||||
/* allowed, all lowercase Latin letters are treated as uppercase. */
|
||||
arg key p /*get key and text to be cyphered*/
|
||||
p=space(p,0) /*remove all blanks from text. */
|
||||
say 'Caesar cypher key:' key
|
||||
say ' plain text:' p
|
||||
y=caesar(p, key) ; say ' cyphered:' y
|
||||
z=caesar(y,-key) ; say ' uncyphered:' z
|
||||
if z\==p then say "plain text doesn't match uncyphered cyphered text."
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────CAESAR subroutine───────────────────*/
|
||||
caesar: procedure; arg s,k; @='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; L=length(@)
|
||||
ak=abs(k)
|
||||
if ak>length(@)-1 | k==0 | k=='' then call err k 'key is invalid'
|
||||
_=verify(s,@) /*any illegal char specified ? */
|
||||
if _\==0 then call err 'unsupported character:' substr(s,_,1)
|
||||
/*now that error checks are done:*/
|
||||
if k>0 then ky=k+1 /*either cypher it, or ··· */
|
||||
else ky=27-ak /* decypher it. */
|
||||
return translate(s,substr(@||@,ky,L),@)
|
||||
/*──────────────────────────────────ERR subroutine──────────────────────*/
|
||||
err: say; say '***error!***'; say; say arg(1); say; exit 13
|
||||
/*REXX program supports the Caesar cypher for the Latin alphabet only, no punctuation */
|
||||
/*──────────── or blanks allowed, all lowercase Latin letters are treated as uppercase.*/
|
||||
parse arg key .; arg . p /*get key & uppercased text to be used.*/
|
||||
p=space(p,0) /*elide any and all spaces (blanks). */
|
||||
say 'Caesar cypher key:' key /*echo the Caesar cypher key to console*/
|
||||
say ' plain text:' p /* " " plain text " " */
|
||||
y=Caesar(p, key); say ' cyphered:' y /* " " cyphered text " " */
|
||||
z=Caesar(y,-key); say ' uncyphered:' z /* " " uncyphered text " " */
|
||||
if z\==p then say "plain text doesn't match uncyphered cyphered text."
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Caesar: procedure; arg s,k; @='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
ak=abs(k) /*obtain the absolute value of the key.*/
|
||||
L=length(@) /*obtain the length of the @ string. */
|
||||
if ak>length(@)-1 | k==0 then call err k 'key is invalid.'
|
||||
_=verify(s,@) /*any illegal characters specified ? */
|
||||
if _\==0 then call err 'unsupported character:' substr(s, _, 1)
|
||||
if k>0 then ky=k+1 /*either cypher it, or ··· */
|
||||
else ky=L+1-ak /* decypher it. */
|
||||
return translate(s, substr(@||@,ky,L),@) /*return the processed text. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
err: say; say '***error***'; say; say arg(1); say; exit 13
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
/*REXX pgm: Caesar cypher for almost all keyboard chars including blanks*/
|
||||
parse arg key p /*get key and text to be cyphered*/
|
||||
say 'Caesar cypher key:' key
|
||||
say ' plain text:' p
|
||||
y=caesar(p, key) ; say ' cyphered:' y
|
||||
z=caesar(y,-key) ; say ' uncyphered:' z
|
||||
if z\==p then say "plain text doesn't match uncyphered cyphered text."
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────CAESAR subroutine───────────────────*/
|
||||
caesar: procedure; parse arg s,k; @='abcdefghijklmnopqrstuvwxyz'
|
||||
@=translate(@)@'0123456789(){}[]<>' /*add uppercase, digs, group symb*/
|
||||
@=@'~!@#$%^&*_+:";?,./`-= ''' /*add other characters here. */
|
||||
/*last char is doubled, REXX quoted syntax rules.*/
|
||||
L=length(@)
|
||||
ak=abs(k)
|
||||
if ak>length(@)-1 | k==0 then call err k 'key is invalid'
|
||||
_=verify(s,@) /*any illegal char specified ? */
|
||||
if _\==0 then call err 'unsupported character:' substr(s,_,1)
|
||||
if k>0 then ky=k+1
|
||||
else ky=L+1-ak
|
||||
return translate(s,substr(@||@,ky,L),@)
|
||||
/*──────────────────────────────────ERR subroutine──────────────────────*/
|
||||
/*REXX program supports the Caesar cypher for most keyboard characters including blanks.*/
|
||||
parse arg key p /*get key and the text to be cyphered. */
|
||||
say 'Caesar cypher key:' key /*echo the Caesar cypher key to console*/
|
||||
say ' plain text:' p /* " " plain text " " */
|
||||
y=Caesar(p, key); say ' cyphered:' y /* " " cyphered text " " */
|
||||
z=Caesar(y,-key); say ' uncyphered:' z /* " " uncyphered text " " */
|
||||
if z\==p then say "plain text doesn't match uncyphered cyphered text."
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Caesar: procedure; parse arg s,k; @= 'abcdefghijklmnopqrstuvwxyz'
|
||||
@=translate(@)@"0123456789(){}[]<>'" /*add uppercase, digitss, group symbols*/
|
||||
@=@'~!@#$%^&*_+:";?,./`-= ' /*also add other characters to the list*/
|
||||
L=length(@) /*obtain the length of the @ string. */
|
||||
ak=abs(k) /*obtain the absolute value of the key.*/
|
||||
if ak>length(@)-1 | k==0 then call err k 'key is invalid.'
|
||||
_=verify(s,@) /*any illegal characters specified ? */
|
||||
if _\==0 then call err 'unsupported character:' substr(s, _, 1)
|
||||
if k>0 then ky=k+1 /*either cypher it, or ··· */
|
||||
else ky=L+1-ak /* decypher it. */
|
||||
return translate(s, substr(@ || @, ky, L), @)
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
err: say; say '***error***'; say; say arg(1); say; exit 13
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue