enigma_ruby 0.1.2 → 0.1.4

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: 12988cada24f1d22f2954abae0f25f952454cb870c3886683f72f32a5fce40c9
4
- data.tar.gz: dcdb04c44fb455aa150932d2ae9dc4f48f1464f958bc2fb216853fc103a1136a
3
+ metadata.gz: 30c3260357339774bee49cb4a35783ce07cadd38a6d74679f2e6bbd3a825ec4e
4
+ data.tar.gz: 1d1b66f1fc5b5822e1010ab97df5edfc5af854fa26ab6cb988d27bd925466c66
5
5
  SHA512:
6
- metadata.gz: 8a9c385e78a24de6d8704702b6e4d55fb2620de00316ec35e29ed9cc6d5bbf2c567c270effafbba69b8d3fd210cbca57cfc8260093a6d92d9929f0fdd3151668
7
- data.tar.gz: 29c215ce716dddb4bfabb17a7f437e98df70f1d8db94a56111de720b54aa2e4dd1bfd153b37012c3ef003801bb6f9518d0d60e8216b9d55b4ec17b32dd109066
6
+ metadata.gz: ffc012733c489f766cfc2fb640f23c138ba80d11c7efa44941e1b5797a64f9f0f627c77008d5c1e43f908bb25d2d22987172a3707ed301d88233a9e6efb69e09
7
+ data.tar.gz: 0532310c2969e3abc6fd00d3a48d96a0319cc5756770738ca8ba0910a543eeb076e85987b4bc48bae915ec6c41c06a0c096203f63be36b5d290abecfb5b0eb49
@@ -0,0 +1,19 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class AdvanceRotors < Base
4
+ def initialize(rotors)
5
+ @rotors = rotors
6
+ end
7
+
8
+ def execute(_)
9
+ @rotors[0].advance
10
+ @rotors.each_with_index do |rotor, i|
11
+ next if i == 0
12
+ break unless @rotors[i - 1].at_notch?
13
+
14
+ rotor.advance
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class Base
4
+ def execute(context)
5
+ raise NotImplementedError, 'Subclasses must implement execute(context)'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class EncodeRotorBackward < Base
4
+ def initialize(rotors)
5
+ @rotors = rotors
6
+ end
7
+
8
+ def execute(context)
9
+ @rotors.reverse_each do |rotor|
10
+ context[:encoded_char] = rotor.encode_backward(context[:encoded_char])
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class EncodeRotorForward < Base
4
+ def initialize(rotors)
5
+ @rotors = rotors
6
+ end
7
+
8
+ def execute(context)
9
+ @rotors.each do |rotor|
10
+ context[:encoded_char] = rotor.encode_forward(context[:encoded_char])
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class Reflect < Base
4
+ def execute(context)
5
+ context[:encoded_char] = Reflector.reflect(context[:encoded_char])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module EnigmaRuby
2
+ module Commands
3
+ class SwapPlugboard < Base
4
+ def execute(context)
5
+ context[:encoded_char] = Plugboard.swap(context[:encoded_char])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -6,12 +6,12 @@ module EnigmaRuby
6
6
  def initialize(rotor_settings = [])
7
7
  initialize_rotors(rotor_settings)
8
8
  @commands = [
9
- SwapPlugboardCommand.new,
10
- EncodeRotorForwardCommand.new(@rotors),
11
- ReflectCommand.new,
12
- EncodeRotorBackwardCommand.new(@rotors),
13
- SwapPlugboardCommand.new,
14
- AdvanceRotorsCommand.new(@rotors)
9
+ Commands::SwapPlugboard.new,
10
+ Commands::EncodeRotorForward.new(@rotors),
11
+ Commands::Reflect.new,
12
+ Commands::EncodeRotorBackward.new(@rotors),
13
+ Commands::SwapPlugboard.new,
14
+ Commands::AdvanceRotors.new(@rotors)
15
15
  ]
16
16
  end
17
17
 
@@ -1,3 +1,3 @@
1
1
  module EnigmaRuby
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/enigma_ruby.rb CHANGED
@@ -3,12 +3,12 @@ require "enigma_ruby/rotor"
3
3
  require "enigma_ruby/reflector"
4
4
  require "enigma_ruby/plugboard"
5
5
  require "enigma_ruby/enigma"
6
- require "enigma_ruby/commands/command"
7
- require "enigma_ruby/commands/advance_rotors_command"
8
- require "enigma_ruby/commands/encode_rotor_backward_command"
9
- require "enigma_ruby/commands/encode_rotor_forward_command"
10
- require "enigma_ruby/commands/reflect_command"
11
- require "enigma_ruby/commands/swap_plugboard_command"
6
+ require "enigma_ruby/commands/base"
7
+ require "enigma_ruby/commands/advance_rotors"
8
+ require "enigma_ruby/commands/encode_rotor_backward"
9
+ require "enigma_ruby/commands/encode_rotor_forward"
10
+ require "enigma_ruby/commands/reflect"
11
+ require "enigma_ruby/commands/swap_plugboard"
12
12
 
13
13
  module EnigmaRuby
14
14
  DEFAULT_ROTOR_SETTINGS = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enigma_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - chibicco
@@ -62,21 +62,24 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - README.md
64
64
  - lib/enigma_ruby.rb
65
- - lib/enigma_ruby/commands/advance_rotors_command.rb
66
- - lib/enigma_ruby/commands/command.rb
67
- - lib/enigma_ruby/commands/encode_rotor_backward_command.rb
68
- - lib/enigma_ruby/commands/encode_rotor_forward_command.rb
69
- - lib/enigma_ruby/commands/reflect_command.rb
70
- - lib/enigma_ruby/commands/swap_plugboard_command.rb
65
+ - lib/enigma_ruby/commands/advance_rotors.rb
66
+ - lib/enigma_ruby/commands/base.rb
67
+ - lib/enigma_ruby/commands/encode_rotor_backward.rb
68
+ - lib/enigma_ruby/commands/encode_rotor_forward.rb
69
+ - lib/enigma_ruby/commands/reflect.rb
70
+ - lib/enigma_ruby/commands/swap_plugboard.rb
71
71
  - lib/enigma_ruby/enigma.rb
72
72
  - lib/enigma_ruby/plugboard.rb
73
73
  - lib/enigma_ruby/reflector.rb
74
74
  - lib/enigma_ruby/rotor.rb
75
75
  - lib/enigma_ruby/version.rb
76
- homepage: https://github.com/chibicco/enigma_ruby/
76
+ homepage: https://github.com/chibicco/enigma_ruby
77
77
  licenses:
78
78
  - MIT
79
- metadata: {}
79
+ metadata:
80
+ homepage_uri: https://github.com/chibicco/enigma_ruby
81
+ source_code_uri: https://github.com/chibicco/enigma_ruby
82
+ rubygems_mfa_required: 'true'
80
83
  post_install_message:
81
84
  rdoc_options: []
82
85
  require_paths:
@@ -85,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - ">="
87
90
  - !ruby/object:Gem::Version
88
- version: '0'
91
+ version: 3.0.0
89
92
  required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ">="
@@ -1,17 +0,0 @@
1
- module EnigmaRuby
2
- class AdvanceRotorsCommand < Command
3
- def initialize(rotors)
4
- @rotors = rotors
5
- end
6
-
7
- def execute(_)
8
- @rotors[0].advance
9
- @rotors.each_with_index do |rotor, i|
10
- next if i == 0
11
- break unless @rotors[i - 1].at_notch?
12
-
13
- rotor.advance
14
- end
15
- end
16
- end
17
- end
@@ -1,7 +0,0 @@
1
- module EnigmaRuby
2
- class Command
3
- def execute(context)
4
- raise NotImplementedError, 'Subclasses must implement execute(context)'
5
- end
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- module EnigmaRuby
2
- class EncodeRotorBackwardCommand < Command
3
- def initialize(rotors)
4
- @rotors = rotors
5
- end
6
-
7
- def execute(context)
8
- @rotors.reverse_each do |rotor|
9
- context[:encoded_char] = rotor.encode_backward(context[:encoded_char])
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module EnigmaRuby
2
- class EncodeRotorForwardCommand < Command
3
- def initialize(rotors)
4
- @rotors = rotors
5
- end
6
-
7
- def execute(context)
8
- @rotors.each do |rotor|
9
- context[:encoded_char] = rotor.encode_forward(context[:encoded_char])
10
- end
11
- end
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- module EnigmaRuby
2
- class ReflectCommand < Command
3
- def execute(context)
4
- context[:encoded_char] = Reflector.reflect(context[:encoded_char])
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module EnigmaRuby
2
- class SwapPlugboardCommand < Command
3
- def execute(context)
4
- context[:encoded_char] = Plugboard.swap(context[:encoded_char])
5
- end
6
- end
7
- end