rotor_machine 1.0.6 → 1.0.7
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 +52 -30
- data/images/Bundesarchiv_Enigma.jpg +0 -0
- data/images/File:Enigma_wiring_kleur.png +0 -0
- data/lib/rotor_machine/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e9e73f3f0d0dc5bf22074adf36c6232392581112ecddd4134ecdc4f64f6dc94
|
4
|
+
data.tar.gz: 934ff208c6cc22b67140633fdbca5f9b18c80a4c057448aad79b8c8859d3b562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4430444a33c8caf979d1854bb48539af1e3da74989a5da10a55cb21b6a415e7bdc46156fd5ee0cfc9c5153488f8667f9fa4e96e13d599236aae7028a96e10156
|
7
|
+
data.tar.gz: 0e4ffc2ff7a4ea276cc239d23a9b8bbf7fe1295f3dfc1376c3d23ed905cb04b4e3d04380fbfa8f8a9595c6c7f9800e4dabda9e434b104ccc4fa78b46cc049082
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# RotorMachine
|
2
2
|
|
3
|
+

|
4
|
+
|
3
5
|
The `RotorMachine` gem provides a simple Ruby implementation of the
|
4
6
|
[Enigma](https://en.wikipedia.org/wiki/Enigma_machine) rotor encryption machine.
|
5
7
|
|
@@ -31,26 +33,30 @@ Or install it yourself as:
|
|
31
33
|
|
32
34
|
## Architecture
|
33
35
|
|
34
|
-
The `RotorMachine::Machine`
|
36
|
+
The [`RotorMachine::Machine`](http://www.rubydoc.info/gems/rotor_machine/RotorMachine/Machine)
|
37
|
+
class serves as the entrypoint and orchestrator for an Enigma machine.
|
35
38
|
|
36
39
|
### Components of an Enigma machine
|
37
40
|
|
38
|
-
The Enigma machine, as represented by the RotorMachine
|
39
|
-
of the following components:
|
41
|
+
The Enigma machine, as represented by the [RotorMachine](http://www.rubydoc.info/gems/rotor_machine)
|
42
|
+
module, consists of the following components:
|
40
43
|
|
41
|
-
* One or more rotors, which
|
42
|
-
rotate to produce a polyalphabetic (rather
|
43
|
-
cipher.
|
44
|
+
* One or more [rotors](http://www.rubydoc.info/gems/rotor_machine/RotorMachine/Rotor), which
|
45
|
+
perform the transposition ciphering and also rotate to produce a polyalphabetic (rather
|
46
|
+
than simple substitution) cipher.
|
44
47
|
|
45
|
-
* A reflector, which
|
48
|
+
* A [reflector](http://www.rubydoc.info/gems/rotor_machine/RotorMachine/Reflector), which
|
49
|
+
performs a simple symmetric substitution of letters
|
46
50
|
|
47
|
-
* A plugboard, which
|
48
|
-
per-message basis.
|
51
|
+
* A [plugboard](http://www.rubydoc.info/gems/rotor_machine/RotorMachine/Plugboard), which
|
52
|
+
allows pairs of letters to be transposed on a per-message basis.
|
49
53
|
|
50
|
-
On an actual Enigma machine, these components are all electromechanical,
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
On an actual Enigma machine, these components are all electromechanical, and
|
55
|
+
the Enigma also included a keyboard, a grid of lights to show the results, and
|
56
|
+
in some cases a printer. Since this is a simulated Enigma, obviously, no
|
57
|
+
keyboard/printer are supplied here. In this simulation, the
|
58
|
+
[Machine](http://www.rubydoc.info/gems/rotor_machine/RotorMachine/Machine)
|
59
|
+
class serves to encapsulate all of these components.
|
54
60
|
|
55
61
|
The polyalphabetic encryption of the Enigma comes from the fact that the
|
56
62
|
rotors are linked (mechanically in a real Enigma) so that they rotate
|
@@ -70,17 +76,19 @@ visit [https://en.wikipedia.org/wiki/Enigma_machine].
|
|
70
76
|
|
71
77
|
### The Signal Path of Letters
|
72
78
|
|
73
|
-
|
74
|
-
|
79
|
+
Here's a visual depiction of the signal path of a single character through
|
80
|
+
a (physical) Enigma machine:
|
81
|
+
|
82
|
+

|
83
|
+
|
84
|
+
As you can see, the electrical signal from a keypress is routed through the
|
85
|
+
plugboard, then through each of the rotors in sequence
|
75
86
|
from left to right. The signal then passes through the reflector (where it
|
76
87
|
is transposed again), then back through the rotors in reverse order, and
|
77
88
|
finally back through the plugboard a second time before being displayed on
|
78
89
|
the light grid and/or printer.
|
79
|
-
|
80
|
-
[https://commons.wikimedia.org/wiki/File:Enigma_wiring_kleur.svg] depicts
|
81
|
-
this visually.
|
82
90
|
|
83
|
-
|
91
|
+
The result of the machine's signal path being a loop is that encryption and
|
84
92
|
decryption are the same operation. That is to say, if you set the rotors
|
85
93
|
and plugboard, and then type your plaintext into the machine, you'll get
|
86
94
|
a string of ciphertext. If you then reset the machine to its initial state
|
@@ -116,12 +124,13 @@ no rotors or reflector.
|
|
116
124
|
require 'rotor_machine'
|
117
125
|
|
118
126
|
machine = RotorMachine::Machine.empty_machine
|
127
|
+
|
119
128
|
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_I, "A", 1)
|
120
129
|
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_II, "A", 1)
|
121
130
|
machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_III, "A", 1)
|
122
131
|
machine.reflector = RotorMachine::Reflector.new(RotorMachine::Reflector::REFLECTOR_A)
|
123
|
-
|
124
|
-
machine.plugboard.connect("Q", "K")
|
132
|
+
|
133
|
+
machine.plugboard.connect("A", "M") machine.plugboard.connect("Q", "K")
|
125
134
|
|
126
135
|
machine.set_rotors("CFL")
|
127
136
|
plaintext = "This is a super secret message".upcase
|
@@ -135,9 +144,12 @@ new_plaintext == plaintext # => true
|
|
135
144
|
|
136
145
|
## Documentation
|
137
146
|
|
138
|
-
The classes in
|
139
|
-
|
140
|
-
|
147
|
+
The classes in
|
148
|
+
[`lib/rotor_machine/`](https://github.com/tammycravit/rotor_machine/tree/master/lib/rotor_machine)
|
149
|
+
all contain [documentation](http://www.rubydoc.info/gems/rotor_machine/) that
|
150
|
+
pretty exhaustively describe their operation.
|
151
|
+
The RSpec tests in the [`spec/`](https://github.com/tammycravit/rotor_machine/tree/master/spec)
|
152
|
+
directory are also instructive for how the library works and how to use it.
|
141
153
|
|
142
154
|
## Development
|
143
155
|
|
@@ -151,12 +163,14 @@ To release a new version, update the version number in `version.rb`, and then
|
|
151
163
|
run `bundle exec rake release`, which will create a git tag for the version,
|
152
164
|
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
153
165
|
|
154
|
-
This gem depends on the `tcravit_ruby_lib`
|
155
|
-
update the version number. You can use the
|
156
|
-
`bundle exec version:bump:
|
157
|
-
to increment the parts of
|
158
|
-
|
159
|
-
`
|
166
|
+
This gem depends on the [`tcravit_ruby_lib`](https://github.com/tammycravit/tcravit_ruby_lib)
|
167
|
+
gem, which provides Rake tasks to update the version number. You can use the
|
168
|
+
`bundle exec rake version:bump:build`, `bundle exec version:bump:minor` and
|
169
|
+
`bundle exec rake version:bump:major` tasks to increment the parts of
|
170
|
+
the version number. (These tasks rewrite the file
|
171
|
+
[`lib/rotor_machine/version.rb`](https://github.com/tammycravit/rotor_machine/blob/master/lib/rotor_machine/version.rb).
|
172
|
+
After using them, you'll need to run a `git add lib/rotor_machine/version.rb`
|
173
|
+
and `git commit -m "version bump"`.
|
160
174
|
|
161
175
|
## Contributing
|
162
176
|
|
@@ -182,3 +196,11 @@ Everyone interacting in the RotorMachine project’s codebases, issue trackers,
|
|
182
196
|
chat rooms and mailing lists is expected to follow the
|
183
197
|
[code of conduct](https://github.com/tammycravit/rotor_machine/blob/master/CODE_OF_CONDUCT.md).
|
184
198
|
|
199
|
+
## Image Credits
|
200
|
+
|
201
|
+
* Enigma image - from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Bundesarchiv_Bild_183-2007-0705-502,_Chiffriermaschine_%22Enigma%22.jpg),
|
202
|
+
provided by Das Bundesarchiv (German Federal Archives).
|
203
|
+
|
204
|
+
* Enigma signal path image - from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Enigma_wiring_kleur.svg),
|
205
|
+
by [MesserWoland](https://commons.wikimedia.org/wiki/User:MesserWoland)
|
206
|
+
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rotor_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammy Cravit
|
@@ -100,6 +100,8 @@ files:
|
|
100
100
|
- bin/console
|
101
101
|
- bin/setup
|
102
102
|
- exe/rotor_machine
|
103
|
+
- images/Bundesarchiv_Enigma.jpg
|
104
|
+
- images/File:Enigma_wiring_kleur.png
|
103
105
|
- lib/rotor_machine.rb
|
104
106
|
- lib/rotor_machine/machine.rb
|
105
107
|
- lib/rotor_machine/plugboard.rb
|