base58 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +10 -8
- data/MIT-LICENSE +4 -4
- data/README.md +126 -0
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/base58.gemspec +21 -35
- data/lib/base58.rb +33 -10
- data/test/test_base58.rb +85 -6
- metadata +26 -37
- data/.gitignore +0 -3
- data/README.rdoc +0 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ec389588355af34bfc88dd2fcf6e8c551461c546a8bf532413536885d6c0bf5e
|
4
|
+
data.tar.gz: 38755386088de0e65513c6ed888f4a6185cecc2168ba28145d207b4c71f80fb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5bfb539ec0b97fddb1c5ac616461959532fbfffdec768c30ba2c810795984a0a563c3f0fff83447ce1b0bb52d5dad1a6751905f9bee9a2d0bef13248a6b02e3
|
7
|
+
data.tar.gz: 4a2e0bbcbb5d1b95cd70b089080257d49666525d07666f415ae1641d047424cbb60096b1aa06f2dfd115ccd538b037337dae95d5a95877f707601f5b2141b192
|
data/CHANGELOG
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
= 0.0
|
2
|
-
-
|
1
|
+
= 0.2.0 [2017-01-05]
|
2
|
+
- Bitcoin and Ripple alphabet support. Thanks to @joelnordell.
|
3
|
+
- Binary encoding and decoding support. Thanks to @joelnordell.
|
3
4
|
|
4
|
-
= 0.0
|
5
|
-
-
|
5
|
+
= 0.1.0 [2010-02-05]
|
6
|
+
- Better argument checking. Thanks to @jimeh.
|
7
|
+
- Add `encode` and `decode` aliases.
|
6
8
|
|
7
|
-
= 0.0.
|
8
|
-
-
|
9
|
+
= 0.0.4 [2009-11-27]
|
10
|
+
- Gracefully deals with bad input. Thanks to @isnotvalid.
|
9
11
|
|
10
|
-
= 0.0.
|
11
|
-
- Initial release.
|
12
|
+
= 0.0.3 [2009-11-05]
|
13
|
+
- Initial release.
|
data/MIT-LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Copyright (c) 2009 Douglas F Shearer
|
2
|
-
|
1
|
+
Copyright (c) 2009 - 2017 Douglas F Shearer
|
2
|
+
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
5
5
|
"Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@ without limitation the rights to use, copy, modify, merge, publish,
|
|
7
7
|
distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
the following conditions:
|
10
|
-
|
10
|
+
|
11
11
|
The above copyright notice and this permission notice shall be
|
12
12
|
included in all copies or substantial portions of the Software.
|
13
|
-
|
13
|
+
|
14
14
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Base58
|
2
|
+
|
3
|
+
Ruby gem for encoding/decoding integers to/from Base58. Supports Flickr, Bitcoin, and Ripple alphabets.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Converting an integer into a Base58 string:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
Base58.int_to_base58(12345) # => "4ER"
|
12
|
+
```
|
13
|
+
|
14
|
+
Converting a Base58 string to the represented integer:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
Base58.base58_to_int("A2Ph") # => 6639914
|
18
|
+
```
|
19
|
+
|
20
|
+
Converting a binary into a Base58 string:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Base58.binary_to_base58("\xCE\xE99\x86".force_encoding('BINARY')) # => "6hKMCS"
|
24
|
+
```
|
25
|
+
|
26
|
+
Converting a Base58 string to the represented binary:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Base58.base58_to_binary("6hKMCS") # => "\xCE\xE99\x86"
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
The package can be installed by adding scatter_swap to your list of dependencies in mix.exs:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
gem install base58
|
39
|
+
```
|
40
|
+
|
41
|
+
Or add it to your Gemfile
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
gem 'base58'
|
45
|
+
```
|
46
|
+
|
47
|
+
The run `bundle install`.
|
48
|
+
|
49
|
+
|
50
|
+
## What is Base58?
|
51
|
+
|
52
|
+
From [Wikipedia](https://en.wikipedia.org/wiki/Base58):
|
53
|
+
|
54
|
+
> Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text. It is similar to Base64 but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is therefore designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string.
|
55
|
+
|
56
|
+
Base58 alphabets are made up of the characters a-z, A-Z, and 0-9, with visually ambiguous characters (0, O, I, l) removed.
|
57
|
+
|
58
|
+
|
59
|
+
## Supported Alphabets
|
60
|
+
|
61
|
+
This library supports three of the most common Base58 alphabets, which have identical, but differently sorted characters.
|
62
|
+
|
63
|
+
Alphabets can be selected by passing a symbol to the second argument of `Base58.int_to_base58` and `Base58.base58_to_int`.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Base58.int_to_base58(12345, :bitcoin)
|
67
|
+
```
|
68
|
+
|
69
|
+
`:flickr` is the default if no second argument is passed.
|
70
|
+
|
71
|
+
|
72
|
+
### Flickr
|
73
|
+
|
74
|
+
Identifier: `:flickr`
|
75
|
+
|
76
|
+
This is the default alphabet. Used to generate [Flickr short URLs](https://www.flickr.com/groups/api/discuss/72157616713786392/). The order of it's characters is numeric, lowercase-alpha, uppercase-alpha.
|
77
|
+
|
78
|
+
123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
|
79
|
+
|
80
|
+
|
81
|
+
### Bitcoin
|
82
|
+
|
83
|
+
Identifier: `:bitcoin`
|
84
|
+
|
85
|
+
The alphabet used by the [Bitcoin](https://en.wikipedia.org/wiki/Bitcoin) protocol. The order of it's characters is numeric, uppercase-alpha, lowercase-alpha.
|
86
|
+
|
87
|
+
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
|
88
|
+
|
89
|
+
|
90
|
+
### Ripple
|
91
|
+
|
92
|
+
Identifier: `:ripple`
|
93
|
+
|
94
|
+
The alphabet used by the [Ripple protocol](https://en.wikipedia.org/wiki/Ripple_(payment_protocol)). The order of the characters were chosen such that the [low values match the primitives of the protocol](http://bitcoin.stackexchange.com/questions/14124/why-is-ripples-base58-alphabet-so-weird).
|
95
|
+
|
96
|
+
rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz
|
97
|
+
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
Source repository is on [Github](https://github.com/dougal/base58), please file issues and pull requests there.
|
102
|
+
|
103
|
+
|
104
|
+
## Documentation
|
105
|
+
|
106
|
+
Documentation can be found online at [RubyDoc.info](http://www.rubydoc.info/github/dougal/base58).
|
107
|
+
|
108
|
+
Alternatively, you can generate docs from the project root with:
|
109
|
+
|
110
|
+
```bash
|
111
|
+
rake rdoc
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
## Credits
|
116
|
+
|
117
|
+
* [Joel Nordell](https://github.com/joelnordell) for Bitcoin and Ripple alphabet support. Also binary encoding support.
|
118
|
+
* [Jim Myhrberg](https://github.com/jimeh) for argument checking and method aliases.
|
119
|
+
|
120
|
+
|
121
|
+
## Copyright and Licence
|
122
|
+
|
123
|
+
Copyright (c) 2009-2018, Douglas F Shearer.
|
124
|
+
|
125
|
+
Base58 is licensed under the MIT Licence.
|
126
|
+
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
|
-
require '
|
4
|
-
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
5
|
desc 'Default: run unit tests.'
|
6
6
|
task :default => :test
|
7
7
|
|
@@ -17,7 +17,7 @@ Rake::RDocTask.new do |rdoc|
|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
18
|
rdoc.title = 'base58'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README.
|
20
|
+
rdoc.rdoc_files.include('README.md')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
22
|
end
|
23
23
|
|
@@ -25,11 +25,11 @@ begin
|
|
25
25
|
require 'jeweler'
|
26
26
|
Jeweler::Tasks.new do |gemspec|
|
27
27
|
gemspec.name = "base58"
|
28
|
-
gemspec.summary = "Base58 is a Ruby library for converting ints to and from base58."
|
28
|
+
gemspec.summary = "Base58 is a Ruby library for converting ints or binaries to and from base58."
|
29
29
|
gemspec.description = gemspec.summary
|
30
30
|
gemspec.email = "dougal.s@gmail.com"
|
31
31
|
gemspec.homepage = "http://github.com/dougal/base58"
|
32
|
-
gemspec.authors = ["Douglas F Shearer"]
|
32
|
+
gemspec.authors = ["Douglas F Shearer"]
|
33
33
|
end
|
34
34
|
Jeweler::GemcutterTasks.new
|
35
35
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/base58.gemspec
CHANGED
@@ -1,48 +1,34 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: base58 0.2.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
8
|
+
s.name = "base58".freeze
|
9
|
+
s.version = "0.2.0"
|
9
10
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Douglas F Shearer".freeze]
|
14
|
+
s.date = "2018-01-05"
|
15
|
+
s.description = "Base58 is a Ruby library for converting ints or binaries to and from base58.".freeze
|
16
|
+
s.email = "dougal.s@gmail.com".freeze
|
15
17
|
s.extra_rdoc_files = [
|
16
|
-
"README.
|
18
|
+
"README.md"
|
17
19
|
]
|
18
20
|
s.files = [
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"lib/base58.rb",
|
27
|
-
"test/test_base58.rb"
|
28
|
-
]
|
29
|
-
s.homepage = %q{http://github.com/dougal/base58}
|
30
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.3.5}
|
33
|
-
s.summary = %q{Base58 is a Ruby library for converting ints to and from base58.}
|
34
|
-
s.test_files = [
|
21
|
+
"CHANGELOG",
|
22
|
+
"MIT-LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"base58.gemspec",
|
27
|
+
"lib/base58.rb",
|
35
28
|
"test/test_base58.rb"
|
36
29
|
]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
s.specification_version = 3
|
41
|
-
|
42
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
-
else
|
44
|
-
end
|
45
|
-
else
|
46
|
-
end
|
30
|
+
s.homepage = "http://github.com/dougal/base58".freeze
|
31
|
+
s.rubygems_version = "2.7.3".freeze
|
32
|
+
s.summary = "Base58 is a Ruby library for converting ints or binaries to and from base58.".freeze
|
47
33
|
end
|
48
34
|
|
data/lib/base58.rb
CHANGED
@@ -1,38 +1,61 @@
|
|
1
1
|
# Base58
|
2
|
-
# Copyright (c) 2009 Douglas F Shearer.
|
2
|
+
# Copyright (c) 2009 - 2017 Douglas F Shearer.
|
3
3
|
# http://douglasfshearer.com
|
4
4
|
# Distributed under the MIT license as included with this plugin.
|
5
5
|
|
6
6
|
class Base58
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# See https://en.wikipedia.org/wiki/Base58
|
9
|
+
ALPHABETS = {
|
10
|
+
flickr: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", # This is the default
|
11
|
+
bitcoin: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", # Also used for IPFS
|
12
|
+
ripple: "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"
|
13
|
+
}
|
14
|
+
|
15
|
+
# NOTE: If adding new alphabets of non-standard length, this should become a method.
|
16
|
+
BASE = ALPHABETS[:flickr].length
|
10
17
|
|
11
18
|
# Converts a base58 string to a base10 integer.
|
12
|
-
def self.base58_to_int(base58_val)
|
19
|
+
def self.base58_to_int(base58_val, alphabet = :flickr)
|
20
|
+
raise ArgumentError, 'Invalid alphabet selection.' unless ALPHABETS.include?(alphabet)
|
13
21
|
int_val = 0
|
14
22
|
base58_val.reverse.split(//).each_with_index do |char,index|
|
15
|
-
raise ArgumentError, 'Value passed not a valid Base58 String.' if (char_index =
|
23
|
+
raise ArgumentError, 'Value passed not a valid Base58 String.' if (char_index = ALPHABETS[alphabet].index(char)).nil?
|
16
24
|
int_val += (char_index)*(BASE**(index))
|
17
25
|
end
|
18
26
|
int_val
|
19
27
|
end
|
20
28
|
|
21
29
|
# Converts a base10 integer to a base58 string.
|
22
|
-
def self.int_to_base58(int_val)
|
30
|
+
def self.int_to_base58(int_val, alphabet = :flickr)
|
23
31
|
raise ArgumentError, 'Value passed is not an Integer.' unless int_val.is_a?(Integer)
|
32
|
+
raise ArgumentError, 'Invalid alphabet selection.' unless ALPHABETS.include?(alphabet)
|
24
33
|
base58_val = ''
|
25
34
|
while(int_val >= BASE)
|
26
35
|
mod = int_val % BASE
|
27
|
-
base58_val =
|
36
|
+
base58_val = ALPHABETS[alphabet][mod,1] + base58_val
|
28
37
|
int_val = (int_val - mod)/BASE
|
29
38
|
end
|
30
|
-
|
39
|
+
ALPHABETS[alphabet][int_val,1] + base58_val
|
40
|
+
end
|
41
|
+
|
42
|
+
# Converts a ASCII-8BIT (binary) encoded string to a base58 string.
|
43
|
+
def self.binary_to_base58(binary_val, alphabet = :flickr)
|
44
|
+
raise ArgumentError, 'Value passed is not a String.' unless binary_val.is_a?(String)
|
45
|
+
raise ArgumentError, 'Value passed is not binary.' unless binary_val.encoding == Encoding::BINARY
|
46
|
+
raise ArgumentError, 'Invalid alphabet selection.' unless ALPHABETS.include?(alphabet)
|
47
|
+
int_to_base58(binary_val.bytes.inject{|a,b|(a<<8)+b}, alphabet)
|
31
48
|
end
|
32
|
-
|
49
|
+
|
50
|
+
# Converts a base58 string to an ASCII-8BIT (binary) encoded string.
|
51
|
+
def self.base58_to_binary(base58_val, alphabet = :flickr)
|
52
|
+
raise ArgumentError, 'Invalid alphabet selection.' unless ALPHABETS.include?(alphabet)
|
53
|
+
[base58_to_int(base58_val, alphabet).to_s(16)].pack('H*')
|
54
|
+
end
|
55
|
+
|
33
56
|
class << self
|
34
57
|
alias_method :encode, :int_to_base58
|
35
58
|
alias_method :decode, :base58_to_int
|
36
59
|
end
|
37
|
-
|
60
|
+
|
38
61
|
end
|
data/test/test_base58.rb
CHANGED
@@ -3,7 +3,9 @@ require 'base58'
|
|
3
3
|
|
4
4
|
class TestBase58 < Test::Unit::TestCase
|
5
5
|
|
6
|
-
EXAMPLES = {
|
6
|
+
EXAMPLES = {
|
7
|
+
:flickr => {
|
8
|
+
"6hKMCS" => 3471391110,
|
7
9
|
"6hDrmR" => 3470152229,
|
8
10
|
"6hHHZB" => 3470988633,
|
9
11
|
"6hHKum" => 3470993664,
|
@@ -502,16 +504,93 @@ EXAMPLES = { "6hKMCS" => 3471391110,
|
|
502
504
|
"6hGMH7" => 3470806020,
|
503
505
|
"6hGp5L" => 3470729904,
|
504
506
|
"6hFfRV" => 3470507135,
|
505
|
-
"6hESHt" => 3470432637
|
507
|
+
"6hESHt" => 3470432637
|
508
|
+
},
|
509
|
+
:bitcoin => {
|
510
|
+
"6Hknds" => 3471391110,
|
511
|
+
"6HeSMr" => 3470152229,
|
512
|
+
"6Hiizc" => 3470988633,
|
513
|
+
"6HikVM" => 3470993664,
|
514
|
+
"6HmGgw" => 3471485480,
|
515
|
+
"6Hcrkr" => 3469844075
|
516
|
+
},
|
517
|
+
:ripple => {
|
518
|
+
"aHk8d1" => 3471391110,
|
519
|
+
"aHeSMi" => 3470152229,
|
520
|
+
"aH55zc" => 3470988633,
|
521
|
+
"aH5kVM" => 3470993664,
|
522
|
+
"aHmGgA" => 3471485480,
|
523
|
+
"aHciki" => 3469844075
|
524
|
+
}
|
525
|
+
}
|
506
526
|
|
507
|
-
|
508
|
-
|
527
|
+
BINARY_STRING_EXAMPLES = {
|
528
|
+
:flickr => {
|
529
|
+
"6hKMCS" => "\xCE\xE99\x86".force_encoding('BINARY'),
|
530
|
+
"6hDrmR" => "\xCE\xD6R%".force_encoding('BINARY'),
|
531
|
+
"6hHHZB" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
|
532
|
+
"6hHKum" => "\xCE\xE3)\x00".force_encoding('BINARY'),
|
533
|
+
"6hLgFW" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
|
534
|
+
"6hBRKR" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
|
535
|
+
},
|
536
|
+
:bitcoin => {
|
537
|
+
"6Hknds" => "\xCE\xE99\x86".force_encoding('BINARY'),
|
538
|
+
"6HeSMr" => "\xCE\xD6R%".force_encoding('BINARY'),
|
539
|
+
"6Hiizc" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
|
540
|
+
"6HikVM" => "\xCE\xE3)\x00".force_encoding('BINARY'),
|
541
|
+
"6HmGgw" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
|
542
|
+
"6Hcrkr" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
|
543
|
+
},
|
544
|
+
:ripple => {
|
545
|
+
"aHk8d1" => "\xCE\xE99\x86".force_encoding('BINARY'),
|
546
|
+
"aHeSMi" => "\xCE\xD6R%".force_encoding('BINARY'),
|
547
|
+
"aH55zc" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
|
548
|
+
"aH5kVM" => "\xCE\xE3)\x00".force_encoding('BINARY'),
|
549
|
+
"aHmGgA" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
|
550
|
+
"aHciki" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
def test_binary_to_base58_all_alphabets
|
555
|
+
BINARY_STRING_EXAMPLES.each do |alphabet, examples|
|
556
|
+
examples.each do |expected, integer|
|
557
|
+
assert_equal expected, Base58.binary_to_base58(integer, alphabet)
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
def test_base58_to_binary_all_alphabets
|
563
|
+
BINARY_STRING_EXAMPLES.each do |alphabet, examples|
|
564
|
+
examples.each do |base_58, expected|
|
565
|
+
assert_equal expected, Base58.base58_to_binary(base_58, alphabet)
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_int_to_base58_all_alphabets
|
571
|
+
EXAMPLES.each do |alphabet, examples|
|
572
|
+
examples.each do |expected, integer|
|
573
|
+
assert_equal expected, Base58.int_to_base58(integer, alphabet)
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
def test_base58_to_int_all_alphabets
|
579
|
+
EXAMPLES.each do |alphabet, examples|
|
580
|
+
examples.each do |base_58, expected|
|
581
|
+
assert_equal expected, Base58.base58_to_int(base_58, alphabet)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
def test_int_to_base58_default_alphabet
|
587
|
+
EXAMPLES[:flickr].each do |expected, integer|
|
509
588
|
assert_equal expected, Base58.int_to_base58(integer)
|
510
589
|
end
|
511
590
|
end
|
512
591
|
|
513
|
-
def
|
514
|
-
EXAMPLES.each do |base_58, expected|
|
592
|
+
def test_base58_to_int_default_alphabet
|
593
|
+
EXAMPLES[:flickr].each do |base_58, expected|
|
515
594
|
assert_equal expected, Base58.base58_to_int(base_58)
|
516
595
|
end
|
517
596
|
end
|
metadata
CHANGED
@@ -1,63 +1,52 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: base58
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Douglas F Shearer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2010-02-05 00:00:00 +00:00
|
13
|
-
default_executable:
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
14
12
|
dependencies: []
|
15
|
-
|
16
|
-
|
13
|
+
description: Base58 is a Ruby library for converting ints or binaries to and from
|
14
|
+
base58.
|
17
15
|
email: dougal.s@gmail.com
|
18
16
|
executables: []
|
19
|
-
|
20
17
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
files:
|
25
|
-
- .gitignore
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.md
|
20
|
+
files:
|
26
21
|
- CHANGELOG
|
27
22
|
- MIT-LICENSE
|
28
|
-
- README.
|
23
|
+
- README.md
|
29
24
|
- Rakefile
|
30
25
|
- VERSION
|
31
26
|
- base58.gemspec
|
32
27
|
- lib/base58.rb
|
33
28
|
- test/test_base58.rb
|
34
|
-
has_rdoc: true
|
35
29
|
homepage: http://github.com/dougal/base58
|
36
30
|
licenses: []
|
37
|
-
|
31
|
+
metadata: {}
|
38
32
|
post_install_message:
|
39
|
-
rdoc_options:
|
40
|
-
|
41
|
-
require_paths:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
42
35
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
45
38
|
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
49
|
-
|
50
|
-
requirements:
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
51
43
|
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
version:
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
55
46
|
requirements: []
|
56
|
-
|
57
47
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
48
|
+
rubygems_version: 2.7.3
|
59
49
|
signing_key:
|
60
|
-
specification_version:
|
61
|
-
summary: Base58 is a Ruby library for converting ints to and from base58.
|
62
|
-
test_files:
|
63
|
-
- test/test_base58.rb
|
50
|
+
specification_version: 4
|
51
|
+
summary: Base58 is a Ruby library for converting ints or binaries to and from base58.
|
52
|
+
test_files: []
|
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
= Base58
|
2
|
-
|
3
|
-
If you find this library useful, please consider a donation to show your support!
|
4
|
-
|
5
|
-
http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
|
6
|
-
|
7
|
-
Paypal address: mailto:dougal.s@gmail.com
|
8
|
-
|
9
|
-
=== Install
|
10
|
-
|
11
|
-
Base58 is hosted by http://gemcutter.com. Please make sure you have added them to your gem sources.
|
12
|
-
|
13
|
-
$ sudo gem install base58
|
14
|
-
|
15
|
-
== Usage
|
16
|
-
|
17
|
-
require 'rubygems'
|
18
|
-
require 'base58'
|
19
|
-
|
20
|
-
# Int to Base58
|
21
|
-
Base58.encode(12345) # => 4ER
|
22
|
-
|
23
|
-
# Base58 to Int
|
24
|
-
Base58.decode('A2Ph') # => 6639914
|
25
|
-
|
26
|
-
== RDoc Documentation
|
27
|
-
|
28
|
-
You can view the rdoc documentation online[http://rdoc.info/projects/dougal/acts_as_indexed/].
|
29
|
-
|
30
|
-
== Problems, Comments, Suggestions?
|
31
|
-
|
32
|
-
All of the above are most welcome. mailto:dougal.s@gmail.com
|
33
|
-
|
34
|
-
|
35
|
-
== Credits
|
36
|
-
|
37
|
-
Douglas F Shearer - http://douglasfshearer.com
|
38
|
-
|
39
|
-
Test examples courtesy Fraser Speirs' Base58Encoder Objective-C class, http://gist.github.com/101674.
|