CIS 554 Scala 2: Playfair Cipher
Fall 2013, David Matuszek
To get you started programming functionally in Scala.
Implement the Playfair Cipher (see the Wikipedia article) for enciphering and deciphering messages. Use this variant:
'j'in the input will be replaced by
'x'will be inserted between them.
"te ll in g" -> "te lx li ng", but
"op po se"does not get an
"xx", insert a
Here is an example input to be encoded:
An anonymous reader sends word of a proof-of-concept Google Chrome browser extension that steals users' login details. The developer, Andreas Grech, says that he is trying to raise awareness about security among end users, and therefore chose Chrome as a test-bed because of its reputation as the safest browser.
"Pennsylvania", here is the code block:
Here is an example encoded output:
fafaw aermw yqnvm vqyns genwm hwoln kqwow ofkpf nexcq wqfvp dckqu vhzwn ynmyz unsig wazcl wpxnv ipxey mpiqf asmvw lbvpx dymvd vaken obefm yinhq pdgyb npxfb zcsvp xzbas cxqki bynfn bonsn yniar wuynd tqbzp vowad sefxe ymnie fzcym ndqkp dfryn dckqu vinlw nyzlv mvyfl xenmg axpmy etwlx lwain zcnyf onyzl kqxny m
Name your project
Playfair, your package
playfair, and your "main" object
main method will interact with the user: It will ask whether to encode, decode, or quit; then (unless quitting) it will ask for the keyword, then it will ask for the name of a file to be encoded/decoded. It will read in the file, encode or decode it, and display the result. This should be repeated until the user quits the program.
Create a class
Coder(keyword: String) with an
encode(plainText: String): String method and a
decode(secretText: String): String method. Use additional classes and objects as you see fit.
Text to be enciphered will be a single
String of arbitrary text. It will be mixed case, with spaces, newlines, and punctuation marks. The return value should be all lowercase; letters should be blocks of 5, with a single space between blocks (the last block may contain fewer than 5 characters); and there will be ten blocks per line (the last line may have fewer blocks). There should be no whitespace at the beginning or the end, and only a single space or a single newline between blocks. All the punctuation should be discarded.
Text to be decoded will be in the format produced by the encoder. The result will have the same structure as the encoded text (blocks of five letters, whitespace as specified above. However, note that the number of blocks, and the number of characters per block, may not be the same as in the encoded file.
Every method, except
main, should be tested with Scalatest. TDD (Test-Driven Development) is strongly recommended. Running the tests should not request input or produce output. Your program will also be tested with our unit tests, so be sure all parameters and results are exactly as specified.
Every method should have Scaladoc comments. Be sure to use the
@author tag in the comment for your
Playfair object, so we know who you are.
The following rules apply to all code except the Scalatest tests.
def, up to a maximum of 5 points.
=>, up to a maximum of 10 points.
Some, and 2 points for each subsequent use of the same method, up to a maximum of 30 points.
while, 5 points for each occurrence of
def main), and 10 points for each occurrence of
null(except in a request for a file). This is to get you to use
List, and maybe
The reasons for these rules are twofold: (1) They are intended to get you using some of the unique Scala constructs, and (2) It is easy to write a program to count these keywords.
Please turn in to Canvas your
zip file by Wednesday, November 13 , before 6:00am.