base45 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +55 -0
- data/README.md +6 -6
- data/Rakefile +3 -3
- data/base45.gemspec +13 -12
- data/bin/console +3 -3
- data/lib/base45/encoding_table.rb +5 -47
- data/lib/base45/version.rb +1 -1
- data/lib/base45.rb +15 -15
- metadata +19 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90f2a21cb5b510525fc9936d7513f1279398b029ed20ba64835ad6e6cb5c1540
|
|
4
|
+
data.tar.gz: 86d3fbe7bbb9fbf152732cf2dff58904d8ae94e4b2c8aab3ef5d75913bc13a44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65c5af1e33830c554e4d047a2f2f40e40037043e5d97242717f4f62bf302bf95890533bc07f1957799cea32a9a5575e2e791bab16fdb254920fbf60e5ab7dd9e
|
|
7
|
+
data.tar.gz: 021a2e76f56bd6038af906bd76c5bf32bf1ceb840f63741f05617f34adbd97647e27cb78ab22956c94a249b89cf8bf8cc1784ec47ac0db6aa74ae46a989859cf
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
source
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
gem
|
|
7
|
+
gem 'rake', '~> 13.0'
|
|
8
8
|
|
|
9
|
-
gem
|
|
9
|
+
gem 'rspec', '~> 3.2'
|
|
10
10
|
|
|
11
|
-
gem
|
|
11
|
+
gem 'rubocop', '~> 1.7'
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
base45 (0.3.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.2)
|
|
10
|
+
diff-lcs (1.4.4)
|
|
11
|
+
parallel (1.21.0)
|
|
12
|
+
parser (3.0.2.0)
|
|
13
|
+
ast (~> 2.4.1)
|
|
14
|
+
rainbow (3.0.0)
|
|
15
|
+
rake (13.0.6)
|
|
16
|
+
regexp_parser (2.1.1)
|
|
17
|
+
rexml (3.2.5)
|
|
18
|
+
rspec (3.10.0)
|
|
19
|
+
rspec-core (~> 3.10.0)
|
|
20
|
+
rspec-expectations (~> 3.10.0)
|
|
21
|
+
rspec-mocks (~> 3.10.0)
|
|
22
|
+
rspec-core (3.10.1)
|
|
23
|
+
rspec-support (~> 3.10.0)
|
|
24
|
+
rspec-expectations (3.10.1)
|
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
26
|
+
rspec-support (~> 3.10.0)
|
|
27
|
+
rspec-mocks (3.10.2)
|
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
29
|
+
rspec-support (~> 3.10.0)
|
|
30
|
+
rspec-support (3.10.2)
|
|
31
|
+
rubocop (1.22.3)
|
|
32
|
+
parallel (~> 1.10)
|
|
33
|
+
parser (>= 3.0.0.0)
|
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
36
|
+
rexml
|
|
37
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
|
38
|
+
ruby-progressbar (~> 1.7)
|
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
40
|
+
rubocop-ast (1.12.0)
|
|
41
|
+
parser (>= 3.0.1.1)
|
|
42
|
+
ruby-progressbar (1.11.0)
|
|
43
|
+
unicode-display_width (2.1.0)
|
|
44
|
+
|
|
45
|
+
PLATFORMS
|
|
46
|
+
x86_64-linux
|
|
47
|
+
|
|
48
|
+
DEPENDENCIES
|
|
49
|
+
base45!
|
|
50
|
+
rake (~> 13.0)
|
|
51
|
+
rspec (~> 3.2)
|
|
52
|
+
rubocop (~> 1.7)
|
|
53
|
+
|
|
54
|
+
BUNDLED WITH
|
|
55
|
+
2.2.27
|
data/README.md
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
The Base45 module provides for the encoding (#encode) and
|
|
4
4
|
decoding (#decode) of binary data using a Base45 representation.
|
|
5
5
|
|
|
6
|
-
Some resources used:
|
|
7
|
-
|
|
8
|
-
* [Base 45 Draft](https://datatracker.ietf.org/doc/draft-faltstrom-base45/)
|
|
9
|
-
* [A JS Base 45 implementation](http://base45-decode-encode.net/)
|
|
10
|
-
* [SO question](https://stackoverflow.com/questions/68114693/decode-base45-string)
|
|
11
|
-
|
|
12
6
|
## Installation
|
|
13
7
|
|
|
14
8
|
Add this line to your application's Gemfile:
|
|
@@ -59,3 +53,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/wattsw
|
|
|
59
53
|
## License
|
|
60
54
|
|
|
61
55
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
56
|
+
|
|
57
|
+
## Resources used
|
|
58
|
+
|
|
59
|
+
* [Base 45 Draft](https://datatracker.ietf.org/doc/draft-faltstrom-base45/)
|
|
60
|
+
* [A JS Base 45 implementation](http://base45-decode-encode.net/)
|
|
61
|
+
* [SO question](https://stackoverflow.com/questions/68114693/decode-base45-string)
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
5
|
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
|
7
7
|
|
|
8
|
-
require
|
|
8
|
+
require 'rubocop/rake_task'
|
|
9
9
|
|
|
10
10
|
RuboCop::RakeTask.new
|
|
11
11
|
|
data/base45.gemspec
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative 'lib/base45/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name =
|
|
6
|
+
spec.name = 'base45'
|
|
7
7
|
spec.version = Base45::VERSION
|
|
8
|
-
spec.authors = [
|
|
9
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['Wattswing']
|
|
9
|
+
spec.email = ['wattswing@gmail.com']
|
|
10
10
|
|
|
11
|
-
spec.summary =
|
|
11
|
+
spec.summary = 'Decode / encode in base 45'
|
|
12
12
|
spec.description = spec.summary
|
|
13
13
|
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.license =
|
|
16
|
-
spec.required_ruby_version =
|
|
14
|
+
spec.homepage = 'https://github.com/wattswing/base45'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
spec.required_ruby_version = '>= 3.0.2'
|
|
17
17
|
|
|
18
|
-
spec.metadata[
|
|
19
|
-
spec.metadata[
|
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
20
20
|
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -25,7 +25,8 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
spec.bindir =
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.require_paths = [
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
|
31
32
|
end
|
data/bin/console
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'base45'
|
|
6
6
|
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -11,5 +11,5 @@ require "base45"
|
|
|
11
11
|
# require "pry"
|
|
12
12
|
# Pry.start
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require 'irb'
|
|
15
15
|
IRB.start(__FILE__)
|
|
@@ -1,53 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Base45
|
|
4
|
-
BASE_45_TABLE =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"04" => "4",
|
|
10
|
-
"05" => "5",
|
|
11
|
-
"06" => "6",
|
|
12
|
-
"07" => "7",
|
|
13
|
-
"08" => "8",
|
|
14
|
-
"09" => "9",
|
|
15
|
-
"10" => "A",
|
|
16
|
-
"11" => "B",
|
|
17
|
-
"12" => "C",
|
|
18
|
-
"13" => "D",
|
|
19
|
-
"14" => "E",
|
|
20
|
-
"15" => "F",
|
|
21
|
-
"16" => "G",
|
|
22
|
-
"17" => "H",
|
|
23
|
-
"18" => "I",
|
|
24
|
-
"19" => "J",
|
|
25
|
-
"20" => "K",
|
|
26
|
-
"21" => "L",
|
|
27
|
-
"22" => "M",
|
|
28
|
-
"23" => "N",
|
|
29
|
-
"24" => "O",
|
|
30
|
-
"25" => "P",
|
|
31
|
-
"26" => "Q",
|
|
32
|
-
"27" => "R",
|
|
33
|
-
"28" => "S",
|
|
34
|
-
"29" => "T",
|
|
35
|
-
"30" => "U",
|
|
36
|
-
"31" => "V",
|
|
37
|
-
"32" => "W",
|
|
38
|
-
"33" => "X",
|
|
39
|
-
"34" => "Y",
|
|
40
|
-
"35" => "Z",
|
|
41
|
-
"36" => " ",
|
|
42
|
-
"37" => "$",
|
|
43
|
-
"38" => "%",
|
|
44
|
-
"39" => "*",
|
|
45
|
-
"40" => "+",
|
|
46
|
-
"41" => "-",
|
|
47
|
-
"42" => ".",
|
|
48
|
-
"43" => "/",
|
|
49
|
-
"44" => ":"
|
|
50
|
-
}.freeze
|
|
4
|
+
BASE_45_TABLE = [
|
|
5
|
+
*('0'..'9').to_a,
|
|
6
|
+
*('A'..'Z').to_a,
|
|
7
|
+
' ', '$', '%', '*', '+', '-', '.', '/', ':'
|
|
8
|
+
].each_with_object({}).with_index { |(index, memo), i| memo[i] = index }
|
|
51
9
|
|
|
52
10
|
INVERTED_BASE_45_TABLE = BASE_45_TABLE.invert.freeze
|
|
53
11
|
end
|
data/lib/base45/version.rb
CHANGED
data/lib/base45.rb
CHANGED
|
@@ -7,17 +7,19 @@
|
|
|
7
7
|
# The Base45 module provides for the encoding (#encode) and
|
|
8
8
|
# decoding (#decode) of binary data using a Base45 representation.
|
|
9
9
|
|
|
10
|
-
require_relative
|
|
11
|
-
require_relative
|
|
12
|
-
require_relative
|
|
10
|
+
require_relative 'base45/version'
|
|
11
|
+
require_relative 'base45/encoding_table'
|
|
12
|
+
require_relative 'base45/errors'
|
|
13
13
|
|
|
14
14
|
# Exposes two methods to decode and encode in base 45
|
|
15
15
|
module Base45
|
|
16
|
+
SQUARE_45 = 45**2
|
|
17
|
+
|
|
16
18
|
class << self
|
|
17
19
|
# Returns the Base45-encoded version of +payload+
|
|
18
20
|
#
|
|
19
21
|
# require 'base45'
|
|
20
|
-
# Base45.encode(
|
|
22
|
+
# Base45.encode('Encoding in base 45 !')
|
|
21
23
|
#
|
|
22
24
|
# <i>Generates:</i>
|
|
23
25
|
#
|
|
@@ -29,24 +31,25 @@ module Base45
|
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
base45_bytes.map do |byte45|
|
|
32
|
-
BASE_45_TABLE[byte45
|
|
34
|
+
BASE_45_TABLE[byte45]
|
|
33
35
|
end.join
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
# Returns the Base45-decoded version of +payload+
|
|
37
39
|
#
|
|
38
40
|
# require 'base45'
|
|
39
|
-
# Base45.encode(
|
|
41
|
+
# Base45.encode(':Y8UPCAVC3/DH44M-DUJCLQE934AW6X0')
|
|
40
42
|
#
|
|
41
43
|
# <i>Generates:</i>
|
|
42
44
|
#
|
|
43
45
|
# Encoding in base 45 !
|
|
44
46
|
def decode(payload)
|
|
45
47
|
map45_chars(payload).each_slice(3).flat_map do |c, d, e|
|
|
46
|
-
|
|
48
|
+
raise ForbiddenLengthError if d.nil?
|
|
49
|
+
|
|
47
50
|
v = c + d * 45
|
|
48
51
|
bytes_from_base45(e, v)
|
|
49
|
-
end.pack(
|
|
52
|
+
end.pack('C*')
|
|
50
53
|
end
|
|
51
54
|
|
|
52
55
|
private
|
|
@@ -54,7 +57,7 @@ module Base45
|
|
|
54
57
|
def bytes_from_base45(last_triplet_byte, factor45)
|
|
55
58
|
return [factor45] unless last_triplet_byte
|
|
56
59
|
|
|
57
|
-
factor45 += last_triplet_byte *
|
|
60
|
+
factor45 += last_triplet_byte * SQUARE_45
|
|
58
61
|
x, y = factor45.divmod(256)
|
|
59
62
|
raise OverflowError unless x < 256
|
|
60
63
|
|
|
@@ -67,18 +70,15 @@ module Base45
|
|
|
67
70
|
|
|
68
71
|
def encode_two_bytes(first_byte, second_byte)
|
|
69
72
|
x = (first_byte << 8) + second_byte
|
|
70
|
-
e, x = x.divmod(
|
|
73
|
+
e, x = x.divmod(SQUARE_45)
|
|
71
74
|
d, c = x.divmod(45)
|
|
72
75
|
|
|
73
76
|
[c, d, e]
|
|
74
77
|
end
|
|
75
78
|
|
|
76
79
|
def map45_chars(string)
|
|
77
|
-
string.
|
|
78
|
-
|
|
79
|
-
raise(IllegalCharacterError, c.inspect) unless char_byte
|
|
80
|
-
|
|
81
|
-
char_byte.to_i
|
|
80
|
+
string.chars.map do |char|
|
|
81
|
+
INVERTED_BASE_45_TABLE[char] || raise(IllegalCharacterError, char)
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: base45
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wattswing
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.2'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.2'
|
|
13
27
|
description: Decode / encode in base 45
|
|
14
28
|
email:
|
|
15
29
|
- wattswing@gmail.com
|
|
@@ -20,6 +34,7 @@ files:
|
|
|
20
34
|
- ".rspec"
|
|
21
35
|
- ".rubocop.yml"
|
|
22
36
|
- Gemfile
|
|
37
|
+
- Gemfile.lock
|
|
23
38
|
- LICENSE.txt
|
|
24
39
|
- README.md
|
|
25
40
|
- Rakefile
|
|
@@ -51,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
51
66
|
- !ruby/object:Gem::Version
|
|
52
67
|
version: '0'
|
|
53
68
|
requirements: []
|
|
54
|
-
rubygems_version: 3.
|
|
69
|
+
rubygems_version: 3.4.22
|
|
55
70
|
signing_key:
|
|
56
71
|
specification_version: 4
|
|
57
72
|
summary: Decode / encode in base 45
|