This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4630f8e
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
pkg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
# b46url | |||
|
|||
## Usage | |||
|
|||
require "b64url" | |||
22507476152874102712.to_b64url # => "Thank-you-4" | |||
"all_the_Fish".from_b64url # => 1961803945217736715041 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
begin; require 'psych'; rescue Object; nil end | |||
require 'rubygems' | |||
require './lib/b64url.rb' | |||
|
|||
begin | |||
require 'jeweler' | |||
Jeweler::Tasks.new do |gemspec| | |||
gemspec.name = "b64url" | |||
gemspec.summary = "Integer to/from base64url converter" | |||
gemspec.email = "pierre@moodstocks.com" | |||
gemspec.homepage = "http://moodstocks.com" | |||
gemspec.description = "Encode and decode integers to/from base64url using the alphabet from RFC 4648" | |||
gemspec.authors = ["Pierre Chapuis"] | |||
gemspec.files = FileList['lib/**/*.rb'] | |||
end | |||
rescue LoadError | |||
puts "Jeweler is not available, please install it first." | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
module B64URL | |||
|
|||
ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" | |||
|
|||
class << self | |||
|
|||
def to_b64url(q) | |||
s = '' | |||
while q != 0 | |||
q,r = q.divmod(64) | |||
s << ALPHA[r] | |||
end | |||
s.reverse! | |||
end | |||
|
|||
def from_b64url(s) | |||
t,m = s.chars.to_a.reverse!.map!{|x| ALPHA.index(x)},1 | |||
t.inject{|r,x| r+x*(m*=64)} | |||
end | |||
|
|||
end | |||
|
|||
end | |||
|
|||
Integer.class_eval do | |||
|
|||
def to_b64url | |||
B64URL.to_b64url(self) | |||
end | |||
|
|||
end | |||
|
|||
String.class_eval do | |||
|
|||
def from_b64url | |||
B64URL.from_b64url(self) | |||
end | |||
|
|||
end |