summaryrefslogtreecommitdiff
path: root/assignments
diff options
context:
space:
mode:
Diffstat (limited to 'assignments')
-rw-r--r--assignments/3-solution.md17
-rw-r--r--assignments/3/caesar.rb10
2 files changed, 27 insertions, 0 deletions
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