rotor_machine 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54bee549dee381db8f08c906984d17aa7a543733f38eb468102b56c7662443f2
4
- data.tar.gz: e72ba384c15532351786ee8d3521e9c3316a230889f8799d5197e40f0749e561
3
+ metadata.gz: 8c6ce5057e6c37a1b68b51d95b163d24a77a082f88a67b5784ca88bfec9c70de
4
+ data.tar.gz: 1fc04d49911e0b2b22b76f4187cbbe17aac542f5125c6c9fb03ad73ba811cf4e
5
5
  SHA512:
6
- metadata.gz: 43f67bbc06116c4c1a3d0ccef333f01ebb4c2eb2ff7b76528b2a03a8be4a4ece9f0f6e226ad34bc227aa6c9ca6323d6ec686ede3fd64026c84a10f08f4cc6c4d
7
- data.tar.gz: 65a8df5ae035d2ff47fb1164ce30470566da792dd7c5a72779f525000f1e99c62b5bd19f0c3378634cccca8029e9546967426e5aea20fc12116abc5d86cd0215
6
+ metadata.gz: 9f9a30fb69dad2d52311d477d832618c3a33f535f966340ff27ce04fc057d65ffe603f0e7fd051e9662647e52fd05c85b834fb6b5badaa30078bc02018fc6800
7
+ data.tar.gz: ece40597dfcb3fee99a900a294a4e9a24dabc4479b09e4a97485ce33f3946ff6104ee50987e13b5e5350486e71009f73caced494685b25e78403f2ece457017e
data/README.md CHANGED
@@ -72,7 +72,7 @@ have position "AAZ", their state after the next character is typed will
72
72
  be "ABA".
73
73
 
74
74
  To learn much more about the inner workings of actual Enigma machines,
75
- visit [https://en.wikipedia.org/wiki/Enigma_machine].
75
+ visit [Enigma Machine (Wikipedia)](https://en.wikipedia.org/wiki/Enigma_machine).
76
76
 
77
77
  ### The Signal Path of Letters
78
78
 
@@ -82,11 +82,11 @@ a (physical) Enigma machine:
82
82
  ![Enigma signal path](https://github.com/tammycravit/rotor_machine/blob/master/images/File:Enigma_wiring_kleur.png?raw=1)
83
83
 
84
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
86
- from left to right. The signal then passes through the reflector (where it
87
- is transposed again), then back through the rotors in reverse order, and
88
- finally back through the plugboard a second time before being displayed on
89
- the light grid and/or printer.
85
+ plugboard, then through each of the rotors in sequence from left to right.
86
+ The signal then passes through the reflector (where it is transposed again),
87
+ then back through the rotors in reverse order, and finally back through the
88
+ plugboard a second time before being displayed on the light grid and/or
89
+ printer.
90
90
 
91
91
  The result of the machine's signal path being a loop is that encryption and
92
92
  decryption are the same operation. That is to say, if you set the rotors
@@ -95,9 +95,10 @@ a string of ciphertext. If you then reset the machine to its initial state
95
95
  and type the ciphertext characters into the machine, you'll produce your
96
96
  original plaintext.
97
97
 
98
- One consequence of the Enigma's design is that a plaintext letter will
99
- never encipher to itself. The Allies were able to exploit this property
100
- to help break the Enigma's encryption in World War II.
98
+ One consequence of the Enigma's design is that a plaintext letter will never
99
+ encipher to itself. The Allies were able to exploit this property to help
100
+ [break the Enigma's encryption](https://en.wikipedia.org/wiki/Cryptanalysis_of_the_Enigma)
101
+ during World War II.
101
102
 
102
103
  ## Usage
103
104
 
@@ -144,7 +145,7 @@ machine.set_rotors("CFL")
144
145
  new_plaintext = machine.encipher(ciphertext) # => "THISI SASUP ERSEC RETME SSAGE"
145
146
  ```
146
147
 
147
- ## Example - Simplified Setup Using the Factory Methods
148
+ ## Example - Simplified Setup Using the Factory
148
149
 
149
150
  ```ruby
150
151
  require 'rotor_machine'
@@ -157,7 +158,6 @@ machine = RotorMachine::Factory.build_machine(
157
158
  machine.set_rotors("CFL")
158
159
 
159
160
  plaintext = "This is a super secret message".upcase
160
-
161
161
  ciphertext = machine.encipher(plaintext) # => "MYGMS ZLTWS AAIDD VTGOC RFKFO"
162
162
 
163
163
  machine.set_rotors("CFL")
@@ -194,7 +194,7 @@ the version number. (These tasks rewrite the file
194
194
  After using them, you'll need to run a `git add lib/rotor_machine/version.rb`
195
195
  and `git commit -m "version bump"`.
196
196
 
197
- ## Contributing
197
+ ### Contributing
198
198
 
199
199
  Bug reports and pull requests are welcome on GitHub at
200
200
  [https://github.com/tammycravit/rotor_machine]. Pull requests for code changes
@@ -207,17 +207,17 @@ contributors are expected to adhere to the
207
207
  Contributions from people who identify as women, BIPOC folx, LGBT folx,
208
208
  and members of other marginalized communities are especially welcomed.
209
209
 
210
- ## License
211
-
212
- The gem is available as open source under the terms of the
213
- [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license.
214
-
215
- ## Code of Conduct
210
+ ### Code of Conduct
216
211
 
217
212
  Everyone interacting in the RotorMachine project’s codebases, issue trackers,
218
213
  chat rooms and mailing lists is expected to follow the
219
214
  [code of conduct](https://github.com/tammycravit/rotor_machine/blob/master/CODE_OF_CONDUCT.md).
220
215
 
216
+ ## License
217
+
218
+ The gem is available as open source under the terms of the
219
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license.
220
+
221
221
  ## Image Credits
222
222
 
223
223
  * Enigma image - from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Bundesarchiv_Bild_183-2007-0705-502,_Chiffriermaschine_%22Enigma%22.jpg),
@@ -121,35 +121,14 @@ module RotorMachine
121
121
  return RotorMachine::Plugboard.new()
122
122
  end
123
123
 
124
- ##
125
- # Build a set of {Rotor}s and return them.
126
- #
127
- # @param rotors [Array] A list of rotor types. Each type should be either
128
- # a symbol corresponding to a constant in the {Rotor} class, or a 26
129
- # character string providing the sequence of letters for the rotor.
130
- # @param initial_positions [String] The starting letter to set each rotor
131
- # to.
132
- # @return [Array] An array of {Rotor} objects.
133
- def build_rotor_set(rotors=[], initial_positions=nil)
134
- ra = rotors.each.collect { |r| build_rotor(rotor_kind: r) }
135
- unless initial_positions.nil?
136
- ra.each_with_index do |r, i|
137
- unless initial_positions[i].nil?
138
- r.position = initial_positions[i]
139
- end
140
- end
141
- end
142
- return ra
143
- end
144
-
145
124
  ##
146
125
  # Build a {Machine} and return it.
147
126
  #
148
127
  # The options hash can provide the following options:
149
128
  #
150
129
  # - `: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}. Alternatively, you can pass an array of
130
+ # manually, or through multiple calls to {#build_rotor}.
131
+ # Alternatively, you can pass an array of
153
132
  # symbols which match the constants in the {Rotor} class, and {Rotor}
154
133
  # objects will be built from those (using default position and step
155
134
  # sizes).
@@ -186,7 +165,7 @@ module RotorMachine
186
165
  end
187
166
  end
188
167
 
189
- m.plugboard = RotorMachine::Plugboard.new()
168
+ m.plugboard = build_plugboard()
190
169
  unless connections.empty?
191
170
  connections.each { |from, to| m.plugboard.connect(from, to) }
192
171
  end
@@ -209,9 +188,5 @@ module RotorMachine
209
188
  ##
210
189
  # {make_machine} is an alias for {build_machine}
211
190
  alias :make_machine :build_machine
212
-
213
- ##
214
- # {make_rotor_set} is an alias for {build_rotor_set}
215
- alias :make_rotor_set :build_rotor_set
216
191
  end
217
192
  end
@@ -88,10 +88,12 @@ module RotorMachine
88
88
  # - Reflector A
89
89
  # - An empty plugboard with no connections
90
90
  def self.default_machine
91
- RotorMachine::Factory.build_machine(
92
- rotors: RotorMachine::Factory::build_rotor_set([:ROTOR_I, :ROTOR_II, :ROTOR_III], "AAA"),
91
+ m = RotorMachine::Factory.build_machine(
92
+ rotors: [:ROTOR_I, :ROTOR_II, :ROTOR_III],
93
93
  reflector: RotorMachine::Factory::build_reflector(reflector_kind: :REFLECTOR_A)
94
94
  )
95
+ m.set_rotors("AAA")
96
+ return m
95
97
  end
96
98
 
97
99
  ##
@@ -116,6 +116,14 @@ module RotorMachine
116
116
  return :CUSTOM
117
117
  end
118
118
 
119
+ ##
120
+ # Return the sequence of letters on the reflector.
121
+ #
122
+ # @return [String] The sequence of letters on the reflector.
123
+ def letters
124
+ @letters.join("")
125
+ end
126
+
119
127
  ##
120
128
  # Get the current letter position of the rotor.
121
129
  #
@@ -1,4 +1,4 @@
1
1
  module RotorMachine
2
- VERSION_DATA = [1, 0, 12]
2
+ VERSION_DATA = [1, 0, 13]
3
3
  VERSION = VERSION_DATA.join(".")
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotor_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammy Cravit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-13 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tcravit_ruby_lib