Playfair cipher: Difference between revisions

Content added Content deleted
(→‎{{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}}: extended the REXX pgm to allow a multi-word cipher (which necessitated changing the order of the 1st two variables). -- ~~~~)
Line 363: 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>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>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, more thanks are due to Walter Pachl for 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.
<br>A fair amount of code was added to massage the decrypted encryption to remove doubled &nbsp; '''X'''es &nbsp; so as to match the original text
<br>(this is the ''possible text'' part of the REXX code).
<lang rexx>/*REXX program implements a PLAYFAIR cipher (encryption & decryption).*/
<lang rexx>/*REXX program implements a PLAYFAIR cipher (encryption & decryption).*/
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc /*lower and upper ABC's.*/
@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.*/
parse arg omit key '(' 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 key =='' | key ==',' then do; key='Playfair example.'; oldK=key " ◄───using the default."; end
if omit=='' | omit==',' then omit='J' /*the "omitted" character. */
if omit=='' | omit==',' then omit='J' /*the "omitted" character. */
Line 373: Line 374:
newKey =scrub(key , 1) /*scrub old cipher key──► newKey */
newKey =scrub(key , 1) /*scrub old cipher key──► newKey */
newText=scrub(text ) /* " " text ──► newText*/
newText=scrub(text ) /* " " text ──► newText*/
if _\=='' then call err 'too many arguments specified.'
if newText=='' then call err 'TEXT is empty or has no letters'
if newText=='' then call err 'TEXT is empty or has no letters'
if length(omit)\==1 then call err 'OMIT letter must be only one letter'
if length(omit)\==1 then call err 'OMIT letter must be only one letter'
Line 470: Line 470:
════════════════Playfair encryption──► decryption──► encryption worked.
════════════════Playfair encryption──► decryption──► encryption worked.
</pre>
</pre>
'''output''' when using the input of: &nbsp; <tt> stuvw x (myteest </tt>
'''output''' when using the input of: &nbsp; <tt> x stuvw (myteest </tt>
<pre>
<pre>
old cipher key: stuvw
old cipher key: stuvw