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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dff3731a08e88906d365f475991967f6f29800ce
4
- data.tar.gz: 622f4078f5a13226208ab4aff323b911bebb9d82
3
+ metadata.gz: 29fa5f2f86ce56a6756c9fb2c6864a576b65a0e0
4
+ data.tar.gz: dc97f15a602319cce3ee4b9338d4c0f61b07c4f4
5
5
  SHA512:
6
- metadata.gz: 6601d0c7bff0a3904557992cefbd36935b103e666f3c7d4616066ce33c6715b17d657b59527ad9e69e5043f09878efe5f19779117cb1f11d7a66b30e420cf609
7
- data.tar.gz: af42b570b9ef6eb7240f23134290d4b0854fc4d2c5a03911449bdd7acf22491d570532755501ac0da0a8fab7d89b40c4fa76cce81716909610ef87e0079f9ead
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(/^(0x)?[0-9a-fA-F]+$/).nil?
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]
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia