A Smart Lock


Build a Lock

You all know what a combination lock is. While you can't probably build a mechanical one, it is fairly simple to simulate one in software.

Let's assume you have a combination lock where the unlocking combination is (10, 23, 7). To open the lock you must:

The lock you simulate in software will have to do something similar, except that there is no knob to turn right or left. Instead you will have to enter all this information from the keyboard.

Your program will read from standard input. Each line in the input is either a 3-tuple which contains

or a line which contains the letter P or p indicating that you want to pull the lock to open.

For the number of times to turn you will use zero if less than a turn is needed to reach the number on the dial, one if you have to make more than a complete turn but less than two, and so on.

For the example above, the required input would then be:

    R  0  10
    L  0  23
    R  1   7
    P

Malformed input will be rejected with an indication of why it's wrong. Examples of wrong input include (but are not limited to):

    K  0  10     *** Wrong direction
    R  8  10     *** Maximum 5 turns!
    R -2  10     *** Wrong number: -2
    R  3  1.0    *** Wrong number: 1.0

The output of your program will be a line indicating whether the lock could be opened or not.

You will find what's the combination for your lock based on your Social Security Number as follows:

  1. D8D7D6 -D5D4 -D3D2D1 D0 is your SSN
  2. Right, D8 mod 6 times, stop at D7D6 mod 25
  3. Left, D5 mod 6 times, stop at D4D3 mod 25
  4. Right, D2 mod 6 times, stop at D1D0 mod 25

If your combination is impossible, like being at 6 and having to turn 0 times to reach 6 (which would be the equivalent of no move), then talk to your instructor to have a lock combination assigned to you.

Break a Lock

Let's now assume that a possible intruder does not have any idea about your lock's combination, but he (should I say she to be PC?) wants to break it. One way to do it is to check all possible combinations. We assume that he knows the limitations of the lock (3-tuple, maximum number of turns is five, etc.). Another possible way to try to break the lock is to generate a random sequence of input strings to the device.


What you'll turn in

  1. A well commented listing of your program (C or C++ is recommended but not required). Note that grading, as described below, considers both the functionality and the readability of your code. You may also want to have a look at a grading sheet used in the past for a similar assignment. If you are unsure about what the documentation of a program means, then you may want to read this document.
  2. A floppy disk (3.5") which contains the source file(s), a DOS executable named comblock.exe and a README file indicating what the program does, how to build the executable, the platform (software and hardware) it's been tested on, and how to run it, plus any other information you consider useful - like the name of the author, disclaimers, etc.
  3. A memo describing what you have done, how and your findings. In the memo clearly state what is the language of the FA(s) you have implemented. Also indicate what is the regular expression(s) corresponding to that language(s). The following will be attachments to the memo:

Grading

  1. A mark between 0 and 10 for functionality. The mark basically indicates in what measure your program works properly and how well you have followed the initial specification.
  2. A mark between 0 and 10 for readability. This mark indicates how well documented your program is; it also considers the general appearance of your final report.
  3. Multiply the above two marks to get the mark for this programming assignment.

For each business day you turn in your project earlier you receive a 5% bonus. However, penalties increase by 5% as well. You can turn in your assignment up to ten business days ahead of the deadline.
Example:

You may be asked to do a code review with your instructor.

Varia

You don't need to be concerned about optimization(s). In particular you are not required to minimize the number of states in your FAs. You can do so if you want but this is not a must.


(c) 1997, Virgil Bistriceanu - virgil@csam.iit.edu
Posted: March 26, 1997. Last update: March 26, 1997