Comp210
Due: 97.Apr.fools (Wed.) in class
The Royal Jailer has a curious habit: Every evening, he turns the key in every door---numbers 1 through 150. Then, he goes back and turns the key in every other door---numbers 2, 4, 6, ..., 150. Then, he goes back and turns the key in every third door---numbers 3, 6, 9, ..., 150. Then, he turns the key in every fourth door---numbers 4, 8, 12, ..., 148. And so on, until he finishes by turning the key in every 150th door (just number 150). After that, he falls asleep, and anybody in an unlocked cell can escape during the night. (At the start of the evening, all cells are locked.)
You and your friends have been framed, and falsely convicted of Meandering with Intent to Jay-walk, and are scheduled to be executed at dawn. Fortunately, each of you can name which cell to be locked away in. Which cell numbers do you-all ask for?
Hints:
Write a function make-passwd-object that takes an initial password and returns a password object. This password object is a function that takes two inputs, an action (a symbol) and a list. There are two possible actions.
The first possible action is 'check-passwd. In this case the list argument contains only one item, the password to be checked. If this password agrees with the current password for the object, then the result of the function call is #t (true). If the password is not correct, the object returns #f (false).
The second possible action is 'set-passwd. In this case the list argument contains two items, the old password and a new password. If the old password agrees with the current password for the object, then the current password is updated to be the new password. Otherwise, the current password for the object remains unchanged. The return value is a boolean indicating whether or not the password was successfully changed.
To prohibit repeated attempts to guess the current password, the object should keep track of failed attempts to check a password or update a password. If there are 4 or more consecutive failed attempts, the object should lock the password object, causing the action invoked via 'check-passwd or 'set-passwd to always fail.
Hint: Maintain the current password and number of consecutive failed attempts as local variables.
Example:
(define my-passwd (make-passwd-object 'secret-handshake)) (define your-passwd (make-passwd-object 'open-sesame)) (my-passwd 'check-passwd (list 'is-this-it?)) ; = #f (my-passwd 'check-passwd (list 'secret-handshake)) ; = #t (my-passwd 'set-passwd (list 'I-forgot 'treasure-map)) ; = #f (my-passwd 'check-passwd (list 'treasure-map)) ; = #f (my-passwd 'check-passwd (list 'secret-handshake)) ; = #t (my-passwd 'set-passwd (list 'secret-handshake 'PROFS-email)) ; = #t (my-passwd 'check-passwd (list 'PROFS-email)) ; = #t (my-passwd 'check-passwd (list 'clumsy-breakin-attempt)) ; = #f (my-passwd 'check-passwd (list 'clumsy-breakin-attempt)) ; = #f (my-passwd 'check-passwd (list 'PROFS-email)) ; = #t (my-passwd 'check-passwd (list 'another-clumsy-breakin-attempt)) ; = #f (my-passwd 'check-passwd (list 'if-at-first) ; = #f (my-passwd 'check-passwd (list 'i-dont-succeed)) ; = #f (my-passwd 'check-passwd (list 'persistence-gets-me-arrested)) ; = #f (my-passwd 'check-passwd (list 'PROFS-email)) ; = #f (my-passwd 'set-passwd (list 'PROFS-email 'ollie)) ; = #f (your-passwd 'check-passwd (list 'open-sesame) ; = #t