crypto-toolbox 0.0.7 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f859d425d099a7e3b6f3ee8539f4696f6634a737
4
- data.tar.gz: a46d807728e9a1a06b5a8fb952b5099c1d6fd120
3
+ metadata.gz: 563d3939c85c919f5a1d27c13ef2ecf6d5571aed
4
+ data.tar.gz: 10eed8131545ee4a29113e9c853356a8d5723073
5
5
  SHA512:
6
- metadata.gz: 3c9dcb0a0f708fe300fb9973ae7ff0af5989e2c2c4e60ae50eb25113b7f1644ec63586bb1eacdcb1b421c514159306920cb1f755e8c5def6b8b2aed2aa440e01
7
- data.tar.gz: f0a06366f6f4b03183dbd77352842d542cc2d9ae79e086cfc90303b545d0b43c73afbd66453ed31f8946c4ba74c45b3f281298cb467fe76b9d0eb43688b302f7
6
+ metadata.gz: 37ee53dad2b745e9415fad735c33bc86bd7c83e5dc6accf76ef261ff1c0c0cfdfe9f30262847edddf401edfca775274f550ceb68ffd54ee1ecd94cb135c8802a
7
+ data.tar.gz: 288b9d5ff55cf655cfe72d0e41c816403515dff7268933359ad0bc7867c67ac462c47dc7ed283ffcb78e3a2ff73fbfb94bc47d3c67b9c638cf1c2236c2a8b856
@@ -2,3 +2,4 @@ require 'crypto-toolbox/crypt_buffer.rb'
2
2
  require 'crypto-toolbox/key_filter.rb'
3
3
  require 'crypto-toolbox/spell_checker.rb'
4
4
  require 'crypto-toolbox/ciphers/caesar.rb'
5
+ require 'crypto-toolbox/ciphers/rot13.rb'
@@ -1,32 +1,38 @@
1
- require 'crypto-toolbox/crypt_buffer'
2
1
 
3
2
  module Ciphers
4
3
  class InvalidCaesarShift < RuntimeError; end
5
4
 
6
5
  class Caesar
7
- def self.encode(msg,shift)
8
- ::Ciphers::Caesar.new.encode(msg,shift)
6
+ def self.encipher(msg,shift)
7
+ ::Ciphers::Caesar.new.encipher(msg,shift)
9
8
  end
10
9
 
11
- def self.decode(msg,shift)
12
- ::Ciphers::Caesar.new.decode(msg,shift)
10
+ def self.decipher(msg,shift)
11
+ ::Ciphers::Caesar.new.decipher(msg,shift)
13
12
  end
14
13
 
15
- def encode(message,shift)
14
+ def encipher(message,shift)
16
15
  assert_valid_shift!(shift)
17
16
  real_shift = convert_shift(shift)
18
17
 
19
- message.split("").map do|part|
20
- part == " " ? part : CryptBuffer.new(part).add(real_shift, mod: 91, offset: 65).str
18
+ message.split("").map do|char|
19
+ mod = (char =~ /[a-z]/) ? 123 : 91
20
+ offset = (char =~ /[a-z]/) ? 97 : 65
21
+
22
+ (char =~ /[^a-zA-Z]/) ? char : CryptBuffer.new(char).add(real_shift, mod: mod, offset: offset).str
21
23
  end.join
22
24
  end
23
25
 
24
- def decode(message,shift)
26
+ def decipher(message,shift)
25
27
  assert_valid_shift!(shift)
26
28
  real_shift = convert_shift(shift)
27
- message.split("").map do |part|
29
+
30
+ message.split("").map do |char|
31
+ mod = (char =~ /[a-z]/) ? 123 : 91
32
+ offset = (char =~ /[a-z]/) ? 97 : 65
33
+
28
34
  # first reduce by 65 to map A to 0 ; then mod-sub with "A"(91)-65; and re-add the 65 to convert back to real ascii A value
29
- part == " " ? part : CryptBuffer(part).sub(65).mod_sub(real_shift,mod: 91-65).add(65).str
35
+ (char =~ /[^a-zA-Z]/) ? char : CryptBuffer(char).sub(offset).mod_sub(real_shift,mod: mod-offset).add(offset).str
30
36
  end.join
31
37
  end
32
38
  private
@@ -38,7 +44,6 @@ module Ciphers
38
44
  def convert_shift(shift)
39
45
  ("A".."Z").to_a.each_with_index.inject({}){|memo,(val,index)| memo[val] = index; memo }[shift]
40
46
  end
41
-
42
47
  end
43
48
 
44
49
  end
@@ -0,0 +1,24 @@
1
+ module Ciphers
2
+ class Rot13
3
+ def self.apply(msg)
4
+ ::Ciphers::Rot13.new.apply(msg)
5
+ end
6
+ def self.encipher(msg)
7
+ ::Ciphers::Rot13.new.apply(msg)
8
+ end
9
+ def self.decipher(msg)
10
+ ::Ciphers::Rot13.new.apply(msg)
11
+ end
12
+
13
+ def apply(message)
14
+ ::Ciphers::Caesar.encipher(message,"N")
15
+ end
16
+ def encipher(message)
17
+ apply(message)
18
+ end
19
+
20
+ def decipher(message)
21
+ apply(message)
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia
@@ -48,6 +48,7 @@ files:
48
48
  - lib/crypto-toolbox.rb
49
49
  - lib/crypto-toolbox/break_vigenere.rb
50
50
  - lib/crypto-toolbox/ciphers/caesar.rb
51
+ - lib/crypto-toolbox/ciphers/rot13.rb
51
52
  - lib/crypto-toolbox/crypt_buffer.rb
52
53
  - lib/crypto-toolbox/key_filter.rb
53
54
  - lib/crypto-toolbox/spell_checker.rb