crypto-toolbox 0.0.2 → 0.0.3
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/crypt_buffer.rb +25 -1
- 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: 29fa5f2f86ce56a6756c9fb2c6864a576b65a0e0
|
4
|
+
data.tar.gz: dc97f15a602319cce3ee4b9338d4c0f61b07c4f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3e04a78bf74013d08f10a5d700335213207f0112eb888b8f608ec58d83221c39c1bc8e57558160687b742710a57c44094fa545667d04bfa12ac942d482d9aac
|
7
|
+
data.tar.gz: 1eb3488edb26cbdf687b8771e4fb55699edca41a49b4ce891e5829b18125e349dcfd2d8563165bf9ca9166fb1a11f36f75ebe0343c4c450d6cce2ff7162b41e9
|
@@ -37,6 +37,26 @@ class CryptBuffer
|
|
37
37
|
map{|b| "%08d" % b.to_s(2) }
|
38
38
|
end
|
39
39
|
|
40
|
+
def modulus(mod)
|
41
|
+
real_mod = sanitize_modulus(mod)
|
42
|
+
CryptBuffer( bytes.map{|b| b % real_mod } )
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def mod_sub(n,mod: 256)
|
47
|
+
end
|
48
|
+
def sub(n)
|
49
|
+
|
50
|
+
end
|
51
|
+
def add(n, mod: 256, offset: 0)
|
52
|
+
real_mod = [256,mod].min
|
53
|
+
|
54
|
+
tmp = bytes.map do |b|
|
55
|
+
val = (b + n) % real_mod
|
56
|
+
val > offset ? val : val+offset
|
57
|
+
end
|
58
|
+
CryptBuffer(tmp)
|
59
|
+
end
|
40
60
|
def xor(input,expand_input: false)
|
41
61
|
if expand_input
|
42
62
|
xor_all_with(input)
|
@@ -67,6 +87,9 @@ class CryptBuffer
|
|
67
87
|
end
|
68
88
|
|
69
89
|
private
|
90
|
+
def sanitize_modulus(mod)
|
91
|
+
(mod > 0) ? mod : 256
|
92
|
+
end
|
70
93
|
def expand_bytes(input,total)
|
71
94
|
if input.length >= total
|
72
95
|
input
|
@@ -83,7 +106,7 @@ class CryptBuffer
|
|
83
106
|
when Array
|
84
107
|
input
|
85
108
|
when String
|
86
|
-
if input.match(/^
|
109
|
+
if input.match(/^0x[0-9a-fA-F]+$/).nil?
|
87
110
|
str2bytes(input)
|
88
111
|
else
|
89
112
|
hex2bytes(normalize_hex(input))
|
@@ -113,6 +136,7 @@ class CryptBuffer
|
|
113
136
|
raise "remove 0x from hexinput"
|
114
137
|
end
|
115
138
|
|
139
|
+
|
116
140
|
def xor_bytes(byt)
|
117
141
|
len = [self.bytes.size,byt.size].min
|
118
142
|
result = self.bytes[0...len].map.with_index{|b,i| b ^ byt[i] } + self.bytes[len,self.bytes.length - len]
|