base58_gmp 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.0.6
2
+ - Update encode API
3
+
1
4
  = 0.0.5
2
5
  - Add Base58 decoding to GMP::Z integer
3
6
  - Add Base58 encoding of GMP::Z integer
@@ -21,14 +21,8 @@ Download and install base58_gmp with the following:
21
21
  # Encode GMP::Z Int as Base58
22
22
  Base58GMP.encode(GMP::Z(12345)) # => 4ER
23
23
 
24
- # Encode Arbitrary Base String as Base58
25
- # Optional second parameter indicates base
26
- # (default 10), and is only used with string input.
27
- # Input must use GMP alphabet.
28
- Base58GMP.encode('3039',16) # => 4ER
29
-
30
24
  # Encode as Base58 using GMP alphabet
31
- Base58GMP.encode(12345, nil, 'gmp') # => 3cn
25
+ Base58GMP.encode(12345, 'gmp') # => 3cn
32
26
 
33
27
  # Decode Base58 as GMP::Z Integer
34
28
  Base58GMP.decode('4ER') # => 12345
@@ -63,7 +57,7 @@ This class requires GMP 4.2.0 or above. Prior versions are limited to Base36.
63
57
 
64
58
  == Problems, Comments, Suggestions?
65
59
 
66
- All of the above are most welcome. mailto:john@johnwang.com
60
+ All of the above are most welcome. mailto:johncwang@gmail.com
67
61
 
68
62
  == Credits
69
63
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'base58_gmp'
3
- s.version = '0.0.5'
4
- s.date = '2011-11-06'
3
+ s.version = '0.0.6'
4
+ s.date = '2011-11-14'
5
5
  s.summary = 'High speed Base58 encoding using GMP with MD5 support'
6
6
  s.description = 'Base58 encoding using the GNU Multiple Precision Arithmetic Library (GMP)'
7
7
  s.authors = ['John Wang']
8
- s.email = 'john@johnwang.com'
8
+ s.email = 'johncwang@gmail.com'
9
9
  s.homepage =
10
10
  'http://rubygems.org/gems/base58_gmp'
11
11
  s.extra_rdoc_files = [
@@ -9,16 +9,13 @@ require 'gmp'
9
9
 
10
10
  class Base58GMP
11
11
 
12
- ALPHABET_GMP = '0-89A-JK-XYZa-fg-kl-v'
13
- ALPHABET_FLICKR = '1-9ab-km-zABC-HJ-NP-Z'
14
-
15
- def self.number_to_base58(number, base = 10, alphabet = 'flickr')
16
- base = 10 unless base.is_a?(Integer)
12
+ ALPHABET_GMP = '0-89A-JK-XYZa-fg-kl-v'
13
+ ALPHABET_FLICKR = '1-9ab-km-zABC-HJ-NP-Z'
14
+ DEFAULT_ALPHABET = 'flickr'
17
15
 
16
+ def self.number_to_base58(number, alphabet=DEFAULT_ALPHABET)
18
17
  base58 = number.is_a?(GMP::Z) ?
19
18
  number.to_s(base = 58) :
20
- number.is_a?(String) ?
21
- GMP::Z(number, base).to_s(base = 58) :
22
19
  GMP::Z(number).to_s(base = 58)
23
20
 
24
21
  alphabet.is_a?(String) && alphabet.downcase == 'gmp' ?
@@ -26,7 +23,10 @@ class Base58GMP
26
23
  self.gmp_to_flickr(base58)
27
24
  end
28
25
 
29
- def self.base58_to_number(base58, alphabet = 'flickr')
26
+ def self.base58_to_number(base58, alphabet=DEFAULT_ALPHABET)
27
+ if !base58.is_a?(String)
28
+ raise ArgumentError, 'Base58 argument is not a string.'
29
+ end
30
30
 
31
31
  unless alphabet.is_a?(String) && alphabet.downcase == 'gmp'
32
32
  base58 = self.flickr_to_gmp(base58)
@@ -35,16 +35,22 @@ class Base58GMP
35
35
  GMP::Z.new(base58, 58)
36
36
  end
37
37
 
38
- def self.gmp_to_flickr(base58_as_gmp)
39
- base58 = base58_as_gmp.tr(ALPHABET_GMP, ALPHABET_FLICKR)
38
+ def self.gmp_to_flickr(base58)
39
+ if !base58.is_a?(String)
40
+ raise ArgumentError, 'Base58 argument is not a string.'
41
+ end
42
+ base58 = base58.tr(ALPHABET_GMP, ALPHABET_FLICKR)
40
43
  end
41
44
 
42
- def self.flickr_to_gmp(base58_as_flickr)
43
- base58 = base58_as_flickr.tr(ALPHABET_FLICKR, ALPHABET_GMP)
45
+ def self.flickr_to_gmp(base58)
46
+ if !base58.is_a?(String)
47
+ raise ArgumentError, 'Base58 argument is not a string.'
48
+ end
49
+ base58 = base58.tr(ALPHABET_FLICKR, ALPHABET_GMP)
44
50
  end
45
51
 
46
- def self.md5_base58(data, alphabet = 'flickr')
47
- self.number_to_base58(Digest::MD5.hexdigest(data).hex, nil, alphabet)
52
+ def self.md5_base58(data, alphabet=DEFAULT_ALPHABET)
53
+ self.number_to_base58(Digest::MD5.hexdigest(data).hex, alphabet)
48
54
  end
49
55
 
50
56
  class << self
@@ -1235,12 +1235,10 @@ class TestBase58GMP < Test::Unit::TestCase
1235
1235
  assert_equal test['b58f'], Base58GMP.encode(test['dec'].to_i)
1236
1236
  assert_equal test['b58f'], Base58GMP.encode(GMP::Z(test['dec'].to_i))
1237
1237
  assert_equal test['b58f'], Base58GMP.encode(test['hex'].to_i(16))
1238
- assert_equal test['b58f'], Base58GMP.encode(test['hex'],16)
1239
1238
  assert_equal test['dec'].to_i, Base58GMP.decode(test['b58f']).to_i
1240
1239
  assert_equal test['hex'] , Base58GMP.decode(test['b58f']).to_s(base=16)
1241
- assert_equal test['b58g'], Base58GMP.encode(test['dec'].to_i,nil,'gmp')
1242
- assert_equal test['b58g'], Base58GMP.encode(test['hex'].to_i(16),nil,'gmp')
1243
- assert_equal test['b58g'], Base58GMP.encode(test['hex'],16,'gmp')
1240
+ assert_equal test['b58g'], Base58GMP.encode(test['dec'].to_i,'gmp')
1241
+ assert_equal test['b58g'], Base58GMP.encode(test['hex'].to_i(16),'gmp')
1244
1242
  assert_equal test['dec'].to_i, Base58GMP.decode(test['b58g'],'gmp').to_i
1245
1243
  assert_equal test['hex'] , Base58GMP.decode(test['b58g'],'gmp').to_s(base=16)
1246
1244
  assert_equal test['b58f'], Base58GMP.md5_base58(test['data'])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base58_gmp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wang
@@ -15,12 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-06 00:00:00 -07:00
18
+ date: 2011-11-14 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
22
  description: Base58 encoding using the GNU Multiple Precision Arithmetic Library (GMP)
23
- email: john@johnwang.com
23
+ email: johncwang@gmail.com
24
24
  executables: []
25
25
 
26
26
  extensions: []