rotor_machine 1.0.11 → 1.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c14a896f17d79c8e20bd1200db2e03b9faa5dd1a8cd54a6f9dc7b09874914c1
4
- data.tar.gz: 1550e595a556ff4c2ae33b89450e66ba25e46f702a8b635b8790f232d858265d
3
+ metadata.gz: 54bee549dee381db8f08c906984d17aa7a543733f38eb468102b56c7662443f2
4
+ data.tar.gz: e72ba384c15532351786ee8d3521e9c3316a230889f8799d5197e40f0749e561
5
5
  SHA512:
6
- metadata.gz: 4f09458966fbaa7ef8e399960a9d2d05cb003504fca2713e0c89d59a710fbb9f7e2b71fd6d2a11f3acfea4ad3cc1c64532c79c2818215d4c2975db823815f1dd
7
- data.tar.gz: 404d1be8f4939c3c141784ef4ffbf8d96cf0dc0a94eb881b9ebda058dc731c827d58446285ff6ef6f2f5f22f9f22ca5bcfa55208cd52b89d307d4ed12e0a6c74
6
+ metadata.gz: 43f67bbc06116c4c1a3d0ccef333f01ebb4c2eb2ff7b76528b2a03a8be4a4ece9f0f6e226ad34bc227aa6c9ca6323d6ec686ede3fd64026c84a10f08f4cc6c4d
7
+ data.tar.gz: 65a8df5ae035d2ff47fb1164ce30470566da792dd7c5a72779f525000f1e99c62b5bd19f0c3378634cccca8029e9546967426e5aea20fc12116abc5d86cd0215
data/README.md CHANGED
@@ -118,6 +118,9 @@ factory methods whcih set up, respectively, a fully configured machine
118
118
  with a default set of rotors and reflector, and an empty machine with
119
119
  no rotors or reflector.
120
120
 
121
+ You can also create a new `RotorMachine::Machine` (or its various parts)
122
+ using the `RotorMachine::Factory` methods, as shown in the second example.
123
+
121
124
  ## Example
122
125
 
123
126
  ```ruby
@@ -130,16 +133,35 @@ machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_II, "A", 1)
130
133
  machine.rotors << RotorMachine::Rotor.new(RotorMachine::Rotor::ROTOR_III, "A", 1)
131
134
  machine.reflector = RotorMachine::Reflector.new(RotorMachine::Reflector::REFLECTOR_A)
132
135
 
133
- machine.plugboard.connect("A", "M") machine.plugboard.connect("Q", "K")
136
+ machine.plugboard.connect("A", "M")
137
+ machine.plugboard.connect("Q", "K")
134
138
 
135
139
  machine.set_rotors("CFL")
136
140
  plaintext = "This is a super secret message".upcase
137
- ciphertext = machine.encipher(plaintext) # => "MYGM AO I VVTDI QZXMGY AOGVIRJ"
141
+ ciphertext = machine.encipher(plaintext) # => "MYGMS ZLTWS AAIDD VTGOC RFKFO"
142
+
143
+ machine.set_rotors("CFL")
144
+ new_plaintext = machine.encipher(ciphertext) # => "THISI SASUP ERSEC RETME SSAGE"
145
+ ```
146
+
147
+ ## Example - Simplified Setup Using the Factory Methods
148
+
149
+ ```ruby
150
+ require 'rotor_machine'
138
151
 
152
+ machine = RotorMachine::Factory.build_machine(
153
+ rotors: [:ROTOR_I, :ROTOR_II, :ROTOR_III],
154
+ reflector: :REFLECTOR_A,
155
+ connections: {"A" => "M", "Q" => "K" }
156
+ )
139
157
  machine.set_rotors("CFL")
140
- new_plaintext = machine.encipher(ciphertext) # => "THIS IS A SUPER SECRET MESSAGE"
141
158
 
142
- new_plaintext == plaintext # => true
159
+ plaintext = "This is a super secret message".upcase
160
+
161
+ ciphertext = machine.encipher(plaintext) # => "MYGMS ZLTWS AAIDD VTGOC RFKFO"
162
+
163
+ machine.set_rotors("CFL")
164
+ new_plaintext = machine.encipher(ciphertext) # => "THISI SASUP ERSEC RETME SSAGE"
143
165
  ```
144
166
 
145
167
  ## Documentation
@@ -148,9 +148,16 @@ module RotorMachine
148
148
  # The options hash can provide the following options:
149
149
  #
150
150
  # - `:rotors` - An array of {Rotor} objects. This can be constructed
151
- # manually, through multiple calls to {#build_rotor}, or through a single
152
- # call to {#build_rotor_set}.
153
- # - `:reflector` - A {Reflector object.
151
+ # manually, through multiple calls to {#build_rotor}, or through a single
152
+ # call to {#build_rotor_set}. Alternatively, you can pass an array of
153
+ # symbols which match the constants in the {Rotor} class, and {Rotor}
154
+ # objects will be built from those (using default position and step
155
+ # sizes).
156
+ #
157
+ # - `:reflector` - A {Reflector} object. Alternatively, a symbol
158
+ # matching one of the reflector type constants can be passed in, and
159
+ # a {Reflector} of the specified type will be created.j
160
+ #
154
161
  # - `:connections` - A {Hash} of connections to make on the new {Machine}'s
155
162
  # {Plugboard}.
156
163
  #
@@ -162,8 +169,23 @@ module RotorMachine
162
169
  connections = options.fetch(:connections, {})
163
170
 
164
171
  m = RotorMachine::Machine.new()
165
- rotors.each { |r| m.rotors << r }
166
- m.reflector = reflector
172
+ rotors.each do |r|
173
+ if r.class.name == "RotorMachine::Rotor"
174
+ m.rotors << r
175
+ elsif r.class.name == "Symbol"
176
+ m.rotors << RotorMachine::Factory.build_rotor(rotor_kind: r)
177
+ end
178
+ end
179
+
180
+ unless reflector.nil?
181
+ if reflector.class.name == "Symbol"
182
+ m.reflector = RotorMachine::Factory.build_reflector(reflector_kind: reflector)
183
+ elsif reflector.class.name == "RotorMachine::Reflector"
184
+ m.reflector = reflector
185
+ else
186
+ end
187
+ end
188
+
167
189
  m.plugboard = RotorMachine::Plugboard.new()
168
190
  unless connections.empty?
169
191
  connections.each { |from, to| m.plugboard.connect(from, to) }
@@ -1,4 +1,4 @@
1
1
  module RotorMachine
2
- VERSION_DATA = [1, 0, 11]
2
+ VERSION_DATA = [1, 0, 12]
3
3
  VERSION = VERSION_DATA.join(".")
4
4
  end
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.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammy Cravit