The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Playfair cipher. Another way of thwarting a simple letter frequency analysis of an encrypted text is to encrypt pairs of letters together. A simple scheme to do this is the Playfair cipher. You pick a keyword and remove duplicate letters from it. Then you fill the keyword, and the remaining letters of the alphabet, into a 5 ??5 square. (Because there are only 25 squares, I and J are considered the same letter.) Here is such an arrangement with the keyword PLAYFAIR:
|
P |
L |
A |
Y |
F |
|
I |
R |
B |
C |
D |
|
E |
G |
H |
K |
M |
|
N |
O |
Q |
S |
T |
|
U |
V |
W |
X |
Z |
To encrypt a letter pair, say AT, look at the rectangle with corners A and T:
|
P |
L |
A |
Y |
F |
|
I |
R |
B |
C |
D |
|
E |
G |
H |
K |
M |
|
N |
O |
Q |
S |
T |
|
U |
V |
W |
X |
Z |
The encoding of this pair is formed by looking at the other two corners of the rectangle— in this case, FQ. If both letters happen to be in the same row or column, such as GO, simply swap the two letters. Decryption is done in the same way.
Write a program that encrypts or decrypts an input text according to this cipher. Use command line arguments as

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll