27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

Implement the Playfair (Wheatstone) Cipher in a script.<br />

The Playfair Cipher encrypts text by substitution of each 2−letter "digram" (grouping). Traditionally,<br />

one would use a 5 x 5 letter scrambled alphabet code key square for the encryption and decryption.<br />

C O D E S<br />

A B F G H<br />

I K L M N<br />

P Q R T U<br />

V W X Y Z<br />

Each letter of the alphabet appears once, except "I" also represents<br />

"J". The arbitrarily chosen key word, "CODES" comes first, then all the<br />

rest of the alphabet, skipping letters already used.<br />

To encrypt, separate the plaintext message into digrams (2−letter<br />

groups). If a group has two identical letters, delete the second, and<br />

form a new group. If there is a single letter left over at the end,<br />

insert a "null" character, typically an "X".<br />

THIS IS A TOP SECRET MESSAGE<br />

TH IS IS AT OP SE CR ET ME SA GE<br />

For each digram, there are three possibilities.<br />

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

1) Both letters will be on the same row of the key square<br />

For each letter, substitute the one immediately to the right, in that<br />

row. If necessary, wrap around left to the beginning of the row.<br />

or<br />

2) Both letters will be in the same column of the key square<br />

For each letter, substitute the one immediately below it, in that<br />

row. If necessary, wrap around to the top of the column.<br />

or<br />

3) Both letters will form the corners of a rectangle within the key<br />

square. For each letter, substitute the one on the other corner the<br />

rectangle which lies on the same row.<br />

The "TH" digram falls under case #3.<br />

G H<br />

M N<br />

T U<br />

(Rectangle with "T" and "H" at corners)<br />

T −−> U<br />

H −−> G<br />

The "SE" digram falls under case #1.<br />

C O D E S (Row containing "S" and "E")<br />

S −−> C (wraps around left to beginning of row)<br />

E −−> S<br />

=========================================================================<br />

To decrypt encrypted text, reverse the above procedure under cases #1<br />

Appendix I. Exercises 438

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!