rotor_machine 1.0.7 → 1.0.8
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/rotor_machine/machine.rb +1 -12
- data/lib/rotor_machine/string_extensions.rb +35 -0
- data/lib/rotor_machine/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7e50d8deefd24a72654bed701b68df31e6b2289ce9bc2f928ac36c1ddd242a
|
4
|
+
data.tar.gz: 3d9a59fa6535f19a90426413dece429cf90a14ed4ce8b7cca8dfc1471613a271
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815e8ceadf35c3f90cc1438bae2e4ce5267a2c7c4bb08e45d24400126479710d6a99c77b877107cd371d7719f226ad231dc6f0e3fedcaf581acd0de507df4681
|
7
|
+
data.tar.gz: 07707fd41ae8daca01075496c38add7f555df67658ea5bc13d0dac6acb146db72b0573d002166e808b64a11144db7ea36860952ad8c79bfa2d6d97f4b4129bea
|
@@ -140,7 +140,7 @@ module RotorMachine
|
|
140
140
|
def encipher(text)
|
141
141
|
raise ArgumentError, "Cannot encipher; no rotors loaded" if (@rotors.count == 0)
|
142
142
|
raise ArgumentError, "Cannot encipher; no reflector loaded" if (@reflector.nil?)
|
143
|
-
|
143
|
+
text.upcase.chars.collect { |c| self.encipher_char(c) }.join("").in_blocks_of(5)
|
144
144
|
end
|
145
145
|
|
146
146
|
##
|
@@ -219,16 +219,5 @@ module RotorMachine
|
|
219
219
|
end
|
220
220
|
ec
|
221
221
|
end
|
222
|
-
|
223
|
-
##
|
224
|
-
# Reformat a string into blocks of letters of uniform size.
|
225
|
-
#
|
226
|
-
# @param the_text [String] The text to reformat.
|
227
|
-
# @param block_size [Numeric] The size of the blocks of letters.
|
228
|
-
# @return [String] The reformatted text.
|
229
|
-
def self.letter_blocks(the_text, block_size)
|
230
|
-
the_text.chars.reject{|s| s.match(/\s/)}.each_slice(block_size).map(&:join).join(" ")
|
231
|
-
end
|
232
|
-
|
233
222
|
end
|
234
223
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
##
|
2
|
+
# String extensions used by the {RotorMachine::Machine} to format output.
|
3
|
+
#
|
4
|
+
# @author Tammy Cravit <tammycravit@me.com>
|
5
|
+
|
6
|
+
class String
|
7
|
+
##
|
8
|
+
# Break a string into blocks of a certain number of characters.
|
9
|
+
#
|
10
|
+
# Encrypted text is often presented in blocks of 5 characters to disguise
|
11
|
+
# word lengths in the ciphertext/plaintext. This method gives Ruby strings
|
12
|
+
# the ability to break themselves into blocks of no more than a specified
|
13
|
+
# number of characters.
|
14
|
+
#
|
15
|
+
# By default, the string is rejoined into a single string, with each
|
16
|
+
# character group separated by a space. To return the string as an array
|
17
|
+
# of chunks instead, pass a false value for the {rejoin} argument.
|
18
|
+
#
|
19
|
+
# @param block_size [Numeric] The maximum size of each block. Defaults
|
20
|
+
# to 5-character blocks if not provided.
|
21
|
+
# @param rejoin [Boolean] True to join the blocks back into a single
|
22
|
+
# string, false to return an array of chunks instead. Defaults to
|
23
|
+
# true.
|
24
|
+
# @return The string with each chunk separated by spaces, or an array of
|
25
|
+
# chunks if {rejoin} is false.
|
26
|
+
def in_blocks_of(block_size=5, rejoin=true)
|
27
|
+
if rejoin
|
28
|
+
self.chars.reject{|s| s.match(/\s/)}.each_slice(block_size).map(&:join).join(" ")
|
29
|
+
else
|
30
|
+
self.chars.reject{|s| s.match(/\s/)}.each_slice(block_size).map(&:join)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
alias :in_blocks :in_blocks_of
|
35
|
+
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.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammy Cravit
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/rotor_machine/plugboard.rb
|
108
108
|
- lib/rotor_machine/reflector.rb
|
109
109
|
- lib/rotor_machine/rotor.rb
|
110
|
+
- lib/rotor_machine/string_extensions.rb
|
110
111
|
- lib/rotor_machine/version.rb
|
111
112
|
- rotor_machine.gemspec
|
112
113
|
homepage: https://github.com/tammycravit/rotor_machine
|