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
def main(args: Array[String])
mainmethod 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, ten blocks per line. This should be repeated until the user quits the program.
class Coder(keyword: String)
def encode(plainText: String): String
Stringof 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. There should be no whitespace at the beginning or the end, and only a single space between blocks. All the punctuation should be discarded.
def decode(secretText: String): String
xbetween double letters (for example,
nxn) should be removed, and an
xqxshould be replaced with
xx. The result should be put into the same format as the encoded text (blocks of five letters, whitespace as specified above). Do not attempt any other "improvements" (replacing
j, inserting punctuation, etc.)
Use additional classes, objects, and methods as you see fit.
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.
Zip your Scala project and submit it via Canvas by 6am Wednesday, November 25.