Jump to content

Playfair cipher: Difference between revisions

→‎{{header|REXX}}: added a thank you in the REXX section header, added a literal to make a couple of error messages easier to peruse (in the program). -- ~~~~
(→‎{{header|REXX}}: added another error check (cipher key can't contain the OMIT character). -- ~~~~)
(→‎{{header|REXX}}: added a thank you in the REXX section header, added a literal to make a couple of error messages easier to peruse (in the program). -- ~~~~)
Line 363:
<br>For ease of viewing and comparing, the output is in capitalized digraphs (which are really ''digrams'') as well as the original input(s).
<br>Thanks to Walter Pachl, this program is now sensitive of using a suitable ''double character'' when &nbsp; '''X''' &nbsp; is present in the cipher key.
<br>Also, more thanks are due to Walter Pachl fir finding that the cipher key can't contain the OMIT character.
<br>Also added a a fair amount of code to massage the decrypted encryption to remove doubled &nbsp; '''X'''es &nbsp; so as to match the original text.
<lang rexx>/*REXX program implements a PLAYFAIR cipher (encryption & decryption).*/
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc /*lower and upper ABC's.*/
parse arg key omit _ . '(' text; /*TEXT is the phrase to be used. */ ;oldK=key /*save old.*/
if key =='' | key ==',' then do; key='Playfair example.'; oldK=key " ◄───using the default."; end
if omit=='' | omit==',' then omit='J' /*the "omitted" character. */
Line 375 ⟶ 377:
if length(omit)\==1 then call err 'OMIT letter must be only one letter'
if \datatype(omit,'M') then call err 'OMIT letter must be a Latin alphabet letter.'
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc
upper omit @abcU /*uppercase OMIT char & alphabet.*/
if pos(omit,newText)\==0 then call err 'TEXT cant='can''t contain the "OMIT" character: ' omit
if pos(omit,newKeynewText) \==0 then call err 'cipherTEXT' key can''t contain the "OMIT" character: ' omitcant
if pos(omit,newKey) \==0 then call err 'cipher key' cant
fill=space(translate(@abcU,, omit), 0) /*elide OMIT char from alphabet. */
xx='X'; if omit==xx then xx='Q' /*char used for double characters*/
Cookies help us deliver our services. By using our services, you agree to our use of cookies.