crypto-toolbox 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crypto-toolbox.rb +1 -0
- data/lib/crypto-toolbox/ciphers/caesar.rb +17 -12
- data/lib/crypto-toolbox/ciphers/rot13.rb +24 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 563d3939c85c919f5a1d27c13ef2ecf6d5571aed
|
4
|
+
data.tar.gz: 10eed8131545ee4a29113e9c853356a8d5723073
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ee53dad2b745e9415fad735c33bc86bd7c83e5dc6accf76ef261ff1c0c0cfdfe9f30262847edddf401edfca775274f550ceb68ffd54ee1ecd94cb135c8802a
|
7
|
+
data.tar.gz: 288b9d5ff55cf655cfe72d0e41c816403515dff7268933359ad0bc7867c67ac462c47dc7ed283ffcb78e3a2ff73fbfb94bc47d3c67b9c638cf1c2236c2a8b856
|
data/lib/crypto-toolbox.rb
CHANGED
@@ -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.
|
8
|
-
::Ciphers::Caesar.new.
|
6
|
+
def self.encipher(msg,shift)
|
7
|
+
::Ciphers::Caesar.new.encipher(msg,shift)
|
9
8
|
end
|
10
9
|
|
11
|
-
def self.
|
12
|
-
::Ciphers::Caesar.new.
|
10
|
+
def self.decipher(msg,shift)
|
11
|
+
::Ciphers::Caesar.new.decipher(msg,shift)
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
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|
|
20
|
-
|
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
|
26
|
+
def decipher(message,shift)
|
25
27
|
assert_valid_shift!(shift)
|
26
28
|
real_shift = convert_shift(shift)
|
27
|
-
|
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
|
-
|
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.
|
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
|