Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit.
  • Loading branch information
dougal committed Apr 25, 2009
0 parents commit fa8683a
Show file tree
Hide file tree
Showing 8 changed files with 670 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
rdoc
*.gem
.DS_Store
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -0,0 +1,2 @@
= 0.0.1
- Initial release.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2009 Douglas F Shearer

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 38 additions & 0 deletions README.rdoc
@@ -0,0 +1,38 @@
= Base58

If you find this library useful, please consider a donation to show your support!

http://www.paypal.com/cgi-bin/webscr?cmd=_send-money

Paypal address: mailto:dougal.s@gmail.com

=== Install

$ gem sources -a http://gems.github.com (you only have to do this once)
$ sudo gem install dougal-base58

== Usage

require 'rubygems'
require 'base58'

# Int to Base58
Base58.int_to_base58(12345) # => 4ER

# Base58 to Int
Base58.base58_to_int('A2Ph') # => 6639914

== RDoc Documentation

You can view the rdoc documentation online[http://douglasfshearer.com/rdoc/base64/].

== Problems, Comments, Suggestions?

All of the above are most welcome. mailto:dougal.s@gmail.com


== Credits

Douglas F Shearer - http://douglasfshearer.com

Test examples courtesy Fraser Speirs' Base58Encoder Objective-C class, http://gist.github.com/101674.
22 changes: 22 additions & 0 deletions Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the base58 library.'
Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/test_*.rb'
t.verbose = false
end

desc 'Generate RDoc documentation.'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'base58'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
36 changes: 36 additions & 0 deletions base58.gemspec
@@ -0,0 +1,36 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{base58}
s.version = "0.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Douglas F Shearer"]
s.date = %q{2009-04-25}
s.description = %q{Base58 is a Ruby library for converting ints to and from base58.}
s.email = %q{dougal.s@gmail.com}
s.files = ['lib/base58.rb', 'test/test_base58.rb', 'CHANGELOG', 'MIT-LICENSE', "Rakefile", 'README.rdoc']
s.has_rdoc = true
s.homepage = %q{http://github.com/dougal/base58}
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = s.name
s.rubygems_version = s.version
s.summary = s.description

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<mime-types>, [">= 1.15"])
s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
else
s.add_dependency(%q<mime-types>, [">= 1.15"])
s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
end
else
s.add_dependency(%q<mime-types>, [">= 1.15"])
s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
end
end
31 changes: 31 additions & 0 deletions lib/base58.rb
@@ -0,0 +1,31 @@
# Base64
# Copyright (c) 2009 Douglas F Shearer.
# http://douglasfshearer.com
# Distributed under the MIT license as included with this plugin.

class Base58

ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
BASE = ALPHABET.length

# Converts a base58 string to a base10 integer.
def self.base58_to_int(base58_val)
int_val = 0
base58_val.reverse.split(//).each_with_index do |char,index|
int_val += (ALPHABET.index(char))*(BASE**(index))
end
int_val
end

# Converts a base10 integer to a base58 string.
def self.int_to_base58(int_val)
base58_val = ''
while(int_val >= BASE)
mod = int_val % BASE
base58_val = ALPHABET[mod,1] + base58_val
int_val = (int_val - mod)/BASE
end
ALPHABET[int_val,1] + base58_val
end

end

0 comments on commit fa8683a

Please sign in to comment.