rotor_machine 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -5
- data/lib/rotor_machine/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52da896d6dbf81dd24ef00e3f9c80c26b9cd48e64441d6be91e37b54710eb1e
|
4
|
+
data.tar.gz: af1fcf7f5cfc1786ae5b33e4c216f387b0d8345f76a270dc5428649ea1ba682f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1878e52b14f84edfd06944815ec7bc97862823be50be3c497a959cfa9fc5f4d502759884568ac38e6e179de52c1f54868ca2650d4dd8033c85bba837a5e328
|
7
|
+
data.tar.gz: cf0017ad6357c67a4f1833bed242f20dbb770baee03c322b7c41e4fc4a8accdc743dde22d23b99b5e770a30d88e969611a3cf3a81621c8d0888acbc3d0bf1c2d
|
data/README.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
# RotorMachine
|
2
2
|
|
3
|
-
The
|
3
|
+
The `RotorMachine` gem provides a simple Ruby implementation of the
|
4
|
+
[Enigma](https://en.wikipedia.org/wiki/Enigma_machine) rotor encryption machine.
|
4
5
|
|
5
|
-
I wrote RotorMachine primarily as an exercise in Test-Driven Development with
|
6
|
+
I wrote RotorMachine primarily as an exercise in Test-Driven Development with
|
7
|
+
RSpec. It is not intended to be efficient or performant, and I wasn't striving much
|
8
|
+
for idiomatic conciseness. My aims were fairly modular code and a relatively
|
9
|
+
complete RSpec test suite.
|
6
10
|
|
7
|
-
Many thanks to Kevin Sylvestre, whose
|
11
|
+
Many thanks to Kevin Sylvestre, whose
|
12
|
+
[blog post](https://ksylvest.com/posts/2015-01-03/the-enigma-machine-using-ruby blog post)
|
13
|
+
helped me understand some aspects of the internal workings of the Enigma and
|
14
|
+
how the signals flowed through the pieces of the machine.
|
8
15
|
|
9
16
|
## Installation
|
10
17
|
|
@@ -22,7 +29,7 @@ Or install it yourself as:
|
|
22
29
|
|
23
30
|
$ gem install rotor_machine
|
24
31
|
|
25
|
-
##
|
32
|
+
## Architecture
|
26
33
|
|
27
34
|
The `RotorMachine::Machine` class serves as the entrypoint and orchestrator for an Enigma machine.
|
28
35
|
|
@@ -81,7 +88,7 @@ One consequence of the Enigma's design is that a plaintext letter will
|
|
81
88
|
never encipher to itself. The Allies were able to exploit this property
|
82
89
|
to help break the Enigma's encryption in World War II.
|
83
90
|
|
84
|
-
|
91
|
+
## Usage
|
85
92
|
|
86
93
|
To use the RotorMachine Enigma machine, you need to perform the following
|
87
94
|
steps:
|
@@ -100,6 +107,35 @@ factory methods whcih set up, respectively, a fully configured machine
|
|
100
107
|
with a default set of rotors and reflector, and an empty machine with
|
101
108
|
no rotors or reflector.
|
102
109
|
|
110
|
+
## Example
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
require 'rotor_machine'
|
114
|
+
|
115
|
+
machine = RotorMachine::Machine.empty_machine
|
116
|
+
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_I, "A", 1)
|
117
|
+
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_II, "A", 1)
|
118
|
+
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_III, "A", 1)
|
119
|
+
machine.reflector = RotorMachine::Reflector.new(RotorMachine::Reflector::REFLECTOR_A)
|
120
|
+
machine.plugboard.connect("A", "M")
|
121
|
+
machine.plugboard.connect("Q", "K")
|
122
|
+
|
123
|
+
machine.set_rotors("CFL")
|
124
|
+
plaintext = "This is a super secret message".upcase
|
125
|
+
ciphertext = machine.encipher(plaintext) # => "MYGM AO I VVTDI QZXMGY AOGVIRJ"
|
126
|
+
|
127
|
+
machine.set_rotors("CFL")
|
128
|
+
new_plaintext = machine.encipher(ciphertext) # => "THIS IS A SUPER SECRET MESSAGE"
|
129
|
+
|
130
|
+
new_plaintext == plaintext # => true
|
131
|
+
```
|
132
|
+
|
133
|
+
## Documentation
|
134
|
+
|
135
|
+
The classes in `rotor_machine/lib/rotor_machine/*.rb` all contain doc comments that
|
136
|
+
pretty exhaustively describe their operation. The RSpec tests in the `spec/` directory
|
137
|
+
are also instructive for how the library works and how to use it.
|
138
|
+
|
103
139
|
## Development
|
104
140
|
|
105
141
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|