bitcoin-cigs 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/bitcoin_cigs/base_58.rb +1 -43
- data/lib/bitcoin_cigs/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/bitcoin_cigs/base_58.rb
CHANGED
@@ -13,7 +13,7 @@ module BitcoinCigs
|
|
13
13
|
|
14
14
|
leading_zeros = /^#{CHARS[0]}*/.match(s).to_s.size
|
15
15
|
|
16
|
-
["#{"
|
16
|
+
["#{"00" * leading_zeros}#{int_val.to_s(16)}"].pack('H*')
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.encode(s)
|
@@ -38,47 +38,5 @@ module BitcoinCigs
|
|
38
38
|
|
39
39
|
result
|
40
40
|
end
|
41
|
-
|
42
|
-
# def self.encode(s)
|
43
|
-
# int_val = s.unpack('H*').first.to_i(16)
|
44
|
-
#
|
45
|
-
# var bi = BigInteger.fromByteArrayUnsigned(input);
|
46
|
-
# var chars = [];
|
47
|
-
#
|
48
|
-
# while (bi.compareTo(B58.base) >= 0) {
|
49
|
-
# var mod = bi.mod(B58.base);
|
50
|
-
# chars.unshift(B58.alphabet[mod.intValue()]);
|
51
|
-
# bi = bi.subtract(mod).divide(B58.base);
|
52
|
-
# }
|
53
|
-
# chars.unshift(B58.alphabet[bi.intValue()]);
|
54
|
-
#
|
55
|
-
# for (var i = 0; i < input.length; i++) {
|
56
|
-
# if (input[i] == 0x00) {
|
57
|
-
# chars.unshift(B58.alphabet[0]);
|
58
|
-
# } else break;
|
59
|
-
# }
|
60
|
-
#
|
61
|
-
# return chars.join('');
|
62
|
-
# end
|
63
|
-
|
64
|
-
# def self.encode(s)
|
65
|
-
# value = 0
|
66
|
-
#
|
67
|
-
# value = s.chars.reverse_each.each_with_index.inject(0) { |acc, (ch, i)| acc + (256 ** i) * ch.ord }
|
68
|
-
#
|
69
|
-
# result = []
|
70
|
-
# while value >= CHAR_SIZE
|
71
|
-
# div, mod = value / CHAR_SIZE, value % CHAR_SIZE
|
72
|
-
# result.unshift(CHARS[mod])
|
73
|
-
# value = div
|
74
|
-
# end
|
75
|
-
# result.unshift(CHARS[value])
|
76
|
-
#
|
77
|
-
# pad_size = s.chars.inject(0) { |acc, ch| acc + (ch == "\0" ? 1 : 0) }
|
78
|
-
#
|
79
|
-
# result.unshift(CHARS[0] * pad_size)
|
80
|
-
#
|
81
|
-
# result.join
|
82
|
-
# end
|
83
41
|
end
|
84
42
|
end
|
data/lib/bitcoin_cigs/version.rb
CHANGED