|
|
Due 04.Apr.06 (Tue) 17:00.
Before you tackle the homework, remind yourself of our general hw policies (includes proof-by-induction tips).
Reading: Rosen 2.4-2.6.
(5pts) Write a function to encode messages by the shift-cipher, as described in Rosen.
;; shift: string/lowercase, number → string/lowercase
;; (Where "string/lowercase" means "{a,...,z}*".)
;; Encode lower-case strings by the shift cipher, as sketched in Rosen.
;; Output not specified for other inputs, e.g. upper case, spaces, punctuation.
;;
(define (shift msg offset) ...)
;Examples:
(shift "pizza" 1) = "qjaab"
(shift "bialy" -2) = "zgyjw"
(shift "pez" 52) = "pez"
(shift (shift "indecipherable" 17) -17) = "indecipherable"
What are some other, more trivial, test-cases?
You may use any language,
though your solution should be well-written in any language.
Clarify for future years:
Turn in your hardcopy, including test cases.
Of course, if your solution involves two distinct tasks,
then clear code will have a distinct function
for each task (plus any helpers).
(The solution set's version is 8 lines, plus comments and test cases).
If using scheme, you may use the provided
teachpack,
which also mentions scheme string- and character- processing functions.
Note that in ASCII, unlike Rosen, the numeric value corresponding to
the character #\a isn't 0 or 1,
but some positive integer constant.
(As always in your programs, don't use magic numbers.)
expt"). Extra credit 6 4pts)
Consider the following naive public-key system
given in Thursday's lecture:
a message m is sent by finding the recipient's public
key p,N, calculating the encrypted version x = p*m mod N,
and sending x.
(The recipient presumably knows the private key q,
a number such that q*(p*m) mod N ≡ m (thus un-doing the encryption).)
You overhear the encrypted message (number) x,
and can also look up the public key p,N, but you don't know the
private key q.
(Attempt to) break the following messages. without using a high-level math program like Mathematica, Maple, or Matlab. (General purpose programming languages are okay.) Describe your approach to breaking the code; if other feasible methods also occur to you, describe them very briefly.
In each case, the messages (strings) are converted to/from integers in the following way:
¹ Sadly, this scheme isn't compatible with unicode, as a byte with leading bit 1 is interepreted as an escape code, meaning that it's info is part of further bytes to specify some large character code from a non-roman character set.
|
|
| Comp280 Home | Please notify us of any broken links, etc. | Last modified 2004.Apr.29. |