From 88e3091bb0a5aa5067a83348ca3c3cf8522bde98 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 22 Jan 2025 11:36:48 -0700 Subject: Finish assignment 3 --- 3431709-assignment-3.pdf | Bin 144185 -> 151482 bytes assignments/3-solution.md | 17 +++++++++++++++++ assignments/3/caesar.rb | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 assignments/3/caesar.rb diff --git a/3431709-assignment-3.pdf b/3431709-assignment-3.pdf index 7fe9214..5112b1d 100644 Binary files a/3431709-assignment-3.pdf and b/3431709-assignment-3.pdf differ diff --git a/assignments/3-solution.md b/assignments/3-solution.md index 843ff0a..eb3e5c0 100644 --- a/assignments/3-solution.md +++ b/assignments/3-solution.md @@ -87,3 +87,20 @@ Chapter 7: ``` Chapter 8: + +> 9. Using a Caesar cipher with s = 5, decode the received message RTAJ TZY FY IF + +```plaintext +| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | + +Key: s = 5 + +| F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | + +| Ciphertext | RTAJ TZY FY IFBS | +| Plaintext | RTAJ TZY FY IF | +``` + +```ruby +!include assignments/3/caesar.rb +``` diff --git a/assignments/3/caesar.rb b/assignments/3/caesar.rb new file mode 100644 index 0000000..bc70f75 --- /dev/null +++ b/assignments/3/caesar.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +key = 5 +alphabet = ('A'..'Z').to_a +cipher = alphabet.rotate(key) +map = Hash[cipher.zip(alphabet)] +map[' '] = ' ' + +ciphertext = "RTAJ TZY FY IFBS" +puts ciphertext.chars.map { |x| map[x] }.join -- cgit v1.2.3