Commit 08fe640
Changed files (4)
assignments/3/caesar.rb
@@ -1,10 +1,26 @@
#!/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
+PLAIN_ALPHABET = ('A'..'Z').to_a
+
+def cipher_alphabet_for(key)
+ PLAIN_ALPHABET.rotate(key)
+end
+
+def decode(ciphertext, key)
+ mapping = Hash[cipher_alphabet_for(key).zip(PLAIN_ALPHABET)]
+ ciphertext.chars.map { |x| mapping[x] || ' ' }.join
+end
+
+key = ENV.fetch("KEY", 5).to_i
+ciphertext = ENV.fetch("CIPHERTEXT", "RTAJ TZY FY IFBS")
+
+width = (PLAIN_ALPHABET.size*2)-1
+puts "# Caesar Cipher"
+puts ""
+puts "| --------------- | --------------------------------------------------- |"
+puts "| Plain Alphabet | #{PLAIN_ALPHABET.join(",").ljust(width)} |"
+puts "| Cipher Alphabet | #{cipher_alphabet_for(key).join(",").ljust(width)} |"
+puts "| --------------- | --------------------------------------------------- |"
+puts "| Key | #{key.to_s.ljust(width)} |"
+puts "| Ciphertext | #{ciphertext.to_s.ljust(width)} |"
+puts "| Plaintext | #{decode(ciphertext, key).to_s.ljust(width)} |"
assignments/3-solution.md
@@ -8,11 +8,20 @@ Chapter 6:
> 13. Write a complete assembly language program (including all necessary pseudo-ops) that reads in a series of integers, one at a time, and outputs the largest and smallest values. The input will consist of a list of integer values
+I wrote the following C code and then used the GNU C Compiler to convert the C
+code into Assembly code for my machine. Below is the C code, compiler command,
+and final assembly code.
+
main.c
```c
!include assignments/3/main.c
```
+bash
+```bash
+$ gcc -S -fverbose-asm -02 main.c
+```
+
main.s
```assembly
!include assignments/3/main.s
3431709-assignment-3.pdf
Binary file
Makefile
@@ -8,7 +8,7 @@ default: 3431709-assignment-1.pdf 3431709-assignment-2.pdf 3431709-assignment-3.
3431709-assignment-2.pdf: assignments/2-solution.md
pandoc -f markdown -t pdf -o 3431709-assignment-2.pdf assignments/2-solution.md
-3431709-assignment-3.pdf: assignments/3-solution.md
+3431709-assignment-3.pdf: assignments/3-solution.md assignments/3/caesar.rb assignments/3/main.c assignments/3/main.s
pandoc -f markdown -t pdf --filter pandoc-include -o 3431709-assignment-3.pdf assignments/3-solution.md
3431709-assignment-4.pdf: assignments/4-solution.md