Playfair Square 'encryption' form

What is it:  The included files are used to encrypt and decrypt messages using the Playfair Square rules (slightly modified).

Credit:  All work done by Liz A. Woodhouse.  Feel free to send comments, suggestions, bug reports to Liz at: law@aros.net.  SEE END OF FILE FOR TERMS/DISCLAIMER/COPYRIGHT.

Note: This is strictly for fun.  It was done to see if I could do it.  However, there may be something useful in the code.  I'm also aware that the error trapping code is spotty/inconsistent, and the encryption/decryption routine isn't fully explained, but that's because I have a hard time understanding it myself...  Also, no aliases are used, so the tables and form must be in the same directory (feel free to alter the form to use an alias).

Instructions: Enter a key in the Key field (up to 25 characters), enter the text to encrypt in the Plain Text field OR enter the text to decrypt in the Cipher Text field, press the Re-Prep Square button after changing the value in the Key field or moving to a new record in that table.  Press the Encode/Decode button to encode plain text or decode cipher text.  Do NOT edit the square.

Explanation:  The Playfair Square (or Playfair Code) was named after English scientist and Parliamentarian Sir Lyon Playfair, and invented by physicist Charles Wheatstone.  The code was used early in World War II.  This form uses only a slightly different approach, as follows:

1. The square is a 10x10 grid.  It is prepped by placing the characters from the key in the grid starting with the first field in the first row, and skipping additional occurrences of any letter.  Once the key is in place, the remainder of the alphabet (case sensitive in my version), the numbers 0 through 9, all other standard US keyboard characters and some extended characters are added to the grid.  No character may appear in the grid twice, and the characters must go into the grid in the same order to decrypt the message.

2. The plain text is broken into pairs of letters, and if any pair consists of the same character twice, the pair is split by placing a Z between the two characters in the plain text, if the last character doesn't have a partner, a Z is added to the end of the plain text (you can choose a character other than Z if you wish - if the characters being separated are Zs or the character without a partner is a Z, X is used instead).

3. The rules of encryption are as follows (decryption is done by performing the exact opposite of these steps): For each character in the plain text (including the added Zs), the 'encrypted' version is the character in its own row and its partner's column.  If the characters are in the same row, the 'encrypted' version is the character to the right (if the plain text character is the last character in the row, the 'encrypted' version would be the first character in the same row).  If the characters are in the same column, the 'encrypted' version is the character below (if the plain text character is the last character in the column, the 'encrypted' version would be the first character in the same column).

The following example (using the original Playfair Square layout of a 5x5 grid, only A-Z allowed, I and J coupled in the grid) is to demonstrate these rules.  Our key in this example is BLACKSTAFF and our message is LESTER DUCK LOVES YOU TOO OSCAR (spaces are omitted in the original version).

1. Set up the grid using the key and omitting repeat letters:

B  L  A  C  K
S  T  F  D  E
G  H  IJ M  N
O  P  Q  R  U
V  W  X  Y  Z

2. Our message is broken into pairs (note that the pair which would have been OO (using the last O from TOO and the first O from OSCAR is separated with a Z, and that the lone R at the end of the message is paired with a Z):

LE ST ER DU CK LO VE SY OU TO OZ OS CA RZ

3. Now we will encrypt each pair according to the rules above:

KT TF DU ER KB BP ZS DV PO SP UV VG KC UY

4. In the original rules, the output is put in groups of five (with additional random characters added at the end to fill out the last group), so we'd end up with:

KTTFD UERKB BPZSD VPOSP UVVG KCUYZ

5. However, in my version, the output is not grouped at all, replacements are simply put out character by character.


Disclaimer/Terms: This information and associated files (PLAYCODE.DB, PLAYCODE.MB, PLAYCODE.PX, PLAYFAIR.DB, PLAYFAIR.FSL, PLAYFAIR.TXT) and code are provided free of charge for any legal use or activity.  Illegal use is strictly prohibited and you are solely responsible for such actions.

All files, information, and other data provided with this file are provided as-is with no implied or explicit warranties of any kind whatsoever.  While I make good-faith efforts to provide accurate information, you should always verify my findings before incorporating this information into your own projects and processes. You are strictly and solely responsible for your use of this information. If you damage your system, data, reputation, ability to work, mental stability, or any other material (or immaterial) asset while using the information in this file or the files included with it, it is your responsibility. Practice safe computing--make a backup!

This file and the files included with it may be redistributed freely under the following terms: All files must be included, this text file may not be altered (include your own file if you wish to include additional information), you may not charge anyone any kind of fee (monetary or otherwise) for this file or its associated files, and credit must be given to the author of these files (leave the cmCredit() method in place).

If you wish to make commercial use of this file or any of its associated files, please contact the author via the email address given at the start of this file.

Copyright 2000, Liz A. Woodhouse.  All rights reserved.
