crypto-toolbox 0.0.6 → 0.0.7
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/ciphers/caesar.rb +8 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f859d425d099a7e3b6f3ee8539f4696f6634a737
|
4
|
+
data.tar.gz: a46d807728e9a1a06b5a8fb952b5099c1d6fd120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c9dcb0a0f708fe300fb9973ae7ff0af5989e2c2c4e60ae50eb25113b7f1644ec63586bb1eacdcb1b421c514159306920cb1f755e8c5def6b8b2aed2aa440e01
|
7
|
+
data.tar.gz: f0a06366f6f4b03183dbd77352842d542cc2d9ae79e086cfc90303b545d0b43c73afbd66453ed31f8946c4ba74c45b3f281298cb467fe76b9d0eb43688b302f7
|
@@ -15,15 +15,19 @@ module Ciphers
|
|
15
15
|
def encode(message,shift)
|
16
16
|
assert_valid_shift!(shift)
|
17
17
|
real_shift = convert_shift(shift)
|
18
|
-
|
18
|
+
|
19
|
+
message.split("").map do|part|
|
20
|
+
part == " " ? part : CryptBuffer.new(part).add(real_shift, mod: 91, offset: 65).str
|
21
|
+
end.join
|
19
22
|
end
|
20
23
|
|
21
24
|
def decode(message,shift)
|
22
25
|
assert_valid_shift!(shift)
|
23
26
|
real_shift = convert_shift(shift)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
message.split("").map do |part|
|
28
|
+
# 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
|
30
|
+
end.join
|
27
31
|
end
|
28
32
|
private
|
29
33
|
|