Due 05.Apr.19 (Tue)
Before you tackle the homework, remind yourself of our general hw policies
Reading: Rosen §§ 6.2, 2.4, 2.5.
(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. 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 4pts) Consider the following naive public-key system (as described 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 knows the private key q, a number such that q⋅(p⋅m) ≡ m (mod N) (thus un-doing the encryption). You overhear only the encrypted message (number) x, and you can also look up the public key 〈p,N〉, but you aren't directly given the private key q.
(Attempt to) break the following messages. without using a high-level math program like Mathematica, Maple, or Matlab, since they know how to break this cipher built-in. (Any 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 many unicode encodings, where 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.
[an error occurred while processing this directive] [an error occurred while processing this directive]