Assignment 2

Due on Wednesday 13th February

You should submit solutions to this h/w via the cms system by 11pm on Wednesday. The point of these questions is to end up with as short a main method as possible by delegating as much of the work as possible to reusable methods, and to learn to write classes. Considering how much you'll probably have to spend thinking and making sense of these questions, I decided to ask only two.

Question 1

This is an elementary cryptanalysis exercise being applied to text in English. Write a program which has methods to handle the following scenario (something of an enhancement to the question from the first homework). You will be given a (fairly big) file of plain text (unencrypted) to acquire your arrays of frequencies of letters and pairs (and triples?). Then you will be given a (fairly small) file of encrypted text having (hopefully!) some roughly similar distributions of letters. The encryption will have been done using a simple substitution cypher (so for example, every 'a' may have been replaced by a 't', and every 'b' by a 'g', and perhaps every 'c' by a space). The encrypted text will be without meaningful spaces (in the sense that any spaces will probably be representing some 'real' character), so the original spaces will have been 'filled' by some other character. Moreover the text which has been encrypted will have had all its letters converted to lowercase letters before encryption -- no uppercase letters will be involved at all in the encrypted text, although this courtesy won't have been applied to the sample plaintext (you should do that yourself). Be aware that spaces and tabs will have been encoded differently, and there may well be adjacent spaces in the original and/or the encrypted version, for example, if the letter 'o' were to be represented by a space, and the letters 't' and 's' replaced by 'v' and 'k' repsectively, then the word "toots" would become "v  vk" . Your program should help you to decrypt this text (it's not reasonable to expect it to fully decrypt it in reasonable time by this method, only to get to a point where, crossword-like, you can guess the rest of the textwe). You should certainly have the following two methods:
  • one method should find the most frequently occuring character (or apparent spaces) in the encrypted text, and output a new copy of this with that symbol replaced by the most frequent symbol found in the 'training' text
  • another method should do the same thing for the most frequently appearing pairs of symbols.

There are various refinements you might like to employ. For example, you might like to find and exploit the frequency of doubled (or repeated) symbols, or try replacing the most frequent symbols or pairs with any of the first half dozen most frequent ones found in the training text. In the end, you will find yourself looking at several potentially partially decrypted texts and using educated guesswork to finish the job. (The text will not involve obscure language or meaning!)

Question 2:

Build a banking system. We may well revisit this later to add some more sophisticated security, but for now you should treat this as an opportunity to play with classes. You should have a class Bank to manufacture banks (and have at least two bank objects contructed), a class Person to make people (and have several different people built), a class Shop to make shops (have at least three shops), a class CredCardCo to make credit card companies (have at least two such companies), a class Employer to make employers (have at least two employers, and consider the possible relationship with the companies already built; think inheritance), and any other classes that you think might be helpful.

You should include such fields and methods as make sense to model the interactions amongst these entities, for example, salaries, purchases, loans, accounts. You should also consider how to ensure reasonable privacy of information (we'll investigate this topic later in the course in rather greater depth), viable approaches to authentication (passwords would be a start ...), and good consistency of data (spending money should result in a transfer of money from the spender to the receiver!). Note that typically a credit card company will charge a percentage (usually in the range of 3% to 5%) on the stated purchase price (thus giving less to the receiver) as a way of getting income. You should design your classes and overall testing program so that it's easy to modify any of the main ingredients (e.g., change interest rates).