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 +4 -4
- data/lib/enigma_ruby/commands/advance_rotors.rb +19 -0
- data/lib/enigma_ruby/commands/base.rb +9 -0
- data/lib/enigma_ruby/commands/encode_rotor_backward.rb +15 -0
- data/lib/enigma_ruby/commands/encode_rotor_forward.rb +15 -0
- data/lib/enigma_ruby/commands/reflect.rb +9 -0
- data/lib/enigma_ruby/commands/swap_plugboard.rb +9 -0
- data/lib/enigma_ruby/enigma.rb +6 -6
- data/lib/enigma_ruby/version.rb +1 -1
- data/lib/enigma_ruby.rb +6 -6
- metadata +13 -10
- data/lib/enigma_ruby/commands/advance_rotors_command.rb +0 -17
- data/lib/enigma_ruby/commands/command.rb +0 -7
- data/lib/enigma_ruby/commands/encode_rotor_backward_command.rb +0 -13
- data/lib/enigma_ruby/commands/encode_rotor_forward_command.rb +0 -13
- data/lib/enigma_ruby/commands/reflect_command.rb +0 -7
- data/lib/enigma_ruby/commands/swap_plugboard_command.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c3260357339774bee49cb4a35783ce07cadd38a6d74679f2e6bbd3a825ec4e
|
4
|
+
data.tar.gz: 1d1b66f1fc5b5822e1010ab97df5edfc5af854fa26ab6cb988d27bd925466c66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,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
|
data/lib/enigma_ruby/enigma.rb
CHANGED
@@ -6,12 +6,12 @@ module EnigmaRuby
|
|
6
6
|
def initialize(rotor_settings = [])
|
7
7
|
initialize_rotors(rotor_settings)
|
8
8
|
@commands = [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
|
data/lib/enigma_ruby/version.rb
CHANGED
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/
|
7
|
-
require "enigma_ruby/commands/
|
8
|
-
require "enigma_ruby/commands/
|
9
|
-
require "enigma_ruby/commands/
|
10
|
-
require "enigma_ruby/commands/
|
11
|
-
require "enigma_ruby/commands/
|
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.
|
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/
|
66
|
-
- lib/enigma_ruby/commands/
|
67
|
-
- lib/enigma_ruby/commands/
|
68
|
-
- lib/enigma_ruby/commands/
|
69
|
-
- lib/enigma_ruby/commands/
|
70
|
-
- lib/enigma_ruby/commands/
|
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:
|
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,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
|