base32-alphabets 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -3
- data/Manifest.txt +0 -1
- data/README.md +284 -287
- data/Rakefile +29 -29
- data/lib/base32-alphabets.rb +43 -43
- data/lib/base32-alphabets/version.rb +21 -23
- data/test/helper.rb +10 -10
- data/test/test_base32_crockford.rb +56 -56
- metadata +17 -14
- data/LICENSE.md +0 -116
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 912dbf29c878e8e779121a3ebdb116beb827d4f88e429f25d65802afec27e988
|
4
|
+
data.tar.gz: cc70df72692906c02837715a9bcaffe31b74f5e5b923946d6cf91724b848a002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ced48b976caae8d2bc8c9af02d063b4663de96a9b38e7e834b1a1491b60ff314197bdd4c13e837934c39d88e97e5eb1fddd8c962ff3e25abe330c231e6ccc2
|
7
|
+
data.tar.gz: 23d29172ebea2d2fe499c572b96a340c31f6ed5146233904d0042c082b6b4ddc766fcb3893ab498faa5476472aa0333774b321e5464b2d9f8bdee513def4cadf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
### 0.0.1 / 2018-03-25
|
2
|
-
|
3
|
-
* Everything is new. First release
|
1
|
+
### 0.0.1 / 2018-03-25
|
2
|
+
|
3
|
+
* Everything is new. First release
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -1,287 +1,284 @@
|
|
1
|
-
# Base32 Encoding / Decoding - 5-Bit Notations / Alphabets - Kai / Crockford / Electrologica
|
2
|
-
|
3
|
-
|
4
|
-
Encode / decode numbers in 5-bit groups (2^5=32)
|
5
|
-
with Kai, Crockford or Electrologica notation / alphabet
|
6
|
-
|
7
|
-
|
8
|
-
* home :: [github.com/
|
9
|
-
* bugs :: [github.com/
|
10
|
-
* gem :: [rubygems.org/gems/base32-alphabets](https://rubygems.org/gems/base32-alphabets)
|
11
|
-
* rdoc :: [rubydoc.info/gems/base32-alphabets](http://rubydoc.info/gems/base32-alphabets)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
[Kai](#kai) •
|
17
|
-
[Crockford](#crockford) •
|
18
|
-
[Electrologica](#electrologica)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
## Kai
|
24
|
-
|
25
|
-
The kai notation / alphabet (`123456789abcdefghijkmnopqrstuvwx`)
|
26
|
-
|
27
|
-
Note: Following base56 - the digit-0 and the letter-l
|
28
|
-
are NOT used in the kai alphabet / notation.
|
29
|
-
|
30
|
-
### Kai (Base32) Notation
|
31
|
-
|
32
|
-
|Kai |Binary |Num|Kai |Binary |Num|Kai |Binary |Num|Kai |Binary |Num|
|
33
|
-
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
34
|
-
| **1** | 00000 |
|
35
|
-
| **2** | 00001 |
|
36
|
-
| **3** | 00010 |
|
37
|
-
| **4** | 00011 |
|
38
|
-
| **5** | 00100 |
|
39
|
-
| **6** | 00101 |
|
40
|
-
| **7** | 00110 |
|
41
|
-
| **8** | 00111 |
|
42
|
-
|
43
|
-
Note: The digit-0 and the letter-l are NOT used in kai.
|
44
|
-
|
45
|
-
|
46
|
-
### Usage - Encode / Decode
|
47
|
-
|
48
|
-
``` ruby
|
49
|
-
require 'base32-alphabets'
|
50
|
-
|
51
|
-
|
52
|
-
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
53
|
-
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
54
|
-
|
55
|
-
pp binary == hex
|
56
|
-
# => true
|
57
|
-
|
58
|
-
str = "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff".gsub( ' ', '' )
|
59
|
-
|
60
|
-
str2 = Kai.encode( hex ) ## (binary) number to text
|
61
|
-
pp str
|
62
|
-
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
63
|
-
pp str2
|
64
|
-
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
65
|
-
pp str == str2
|
66
|
-
# => true
|
67
|
-
pp Kai.fmt( str2 )
|
68
|
-
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
69
|
-
pp Kai.fmt( hex ) # all-in-one "shortcut" for Kai.fmt( Kai.encode( hex ))
|
70
|
-
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
71
|
-
|
72
|
-
hex2 = Kai.decode( str2 ) ## text to (binary) number
|
73
|
-
pp hex
|
74
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
75
|
-
pp hex2
|
76
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
77
|
-
pp hex == hex2
|
78
|
-
# => true
|
79
|
-
|
80
|
-
pp = Kai.bytes( hex )
|
81
|
-
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
82
|
-
pp = Kai.bytes( str ) # or from a kai string (auto-decodes to hex first)
|
83
|
-
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
84
|
-
```
|
85
|
-
|
86
|
-
or
|
87
|
-
|
88
|
-
|
89
|
-
``` ruby
|
90
|
-
Base32.format = :kai
|
91
|
-
|
92
|
-
str = Base32.encode( hex ) ## (binary) number to text
|
93
|
-
pp str
|
94
|
-
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
95
|
-
pp Base32.fmt( str )
|
96
|
-
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
97
|
-
pp Base32.fmt( hex ) # all-in-one "shortcut" for Base32.fmt( Base32.encode( hex ))
|
98
|
-
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
99
|
-
pp = Base32.decode( str ) ## text to (binary) number
|
100
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
101
|
-
pp = Base32.bytes( hex )
|
102
|
-
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
103
|
-
pp = Base32.bytes( str ) # or from a kai string (auto-decodes to hex first)
|
104
|
-
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
105
|
-
```
|
106
|
-
|
107
|
-
|
108
|
-
### Why Kai?
|
109
|
-
|
110
|
-
The Kai notation / alphabet is named in honor of Kai Turner
|
111
|
-
who first deciphered the CryptoKitties 256-bit genes in 5-bit groups - thanks!
|
112
|
-
See [The CryptoKitties Genome Project: On Dominance, Inheritance and Mutation](https://medium.com/@kaigani/the-cryptokitties-genome-project-on-dominance-inheritance-and-mutation-b73059dcd0a4), January 2018.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
## Crockford
|
120
|
-
|
121
|
-
The crockford notation / alphabet (`0123456789abcdefghjkmnpqrstvwxyz`)
|
122
|
-
|
123
|
-
Note: The Crockford Base32 symbol set is a superset of the Base16 (hexadecimal) symbol set
|
124
|
-
and starts counting at zero (0).
|
125
|
-
|
126
|
-
|
127
|
-
### Crockford (Base32) Notation
|
128
|
-
|
129
|
-
|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|
|
130
|
-
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
131
|
-
| **0** | 00000 |
|
132
|
-
| **1** | 00001 |
|
133
|
-
| **2** | 00010 |
|
134
|
-
| **3** | 00011 |
|
135
|
-
| **4** | 00100 |
|
136
|
-
| **5** | 00101 |
|
137
|
-
| **6** | 00110 |
|
138
|
-
| **7** | 00111 |
|
139
|
-
|
140
|
-
Note: 4 of the 26 letters are excluded: I L O U.
|
141
|
-
|
142
|
-
- I Can be confused with 1
|
143
|
-
- L Can be confused with 1
|
144
|
-
- O Can be confused with 0
|
145
|
-
- U Accidental obscenity
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
### Usage - Encode / Decode
|
150
|
-
|
151
|
-
``` ruby
|
152
|
-
require 'base32-alphabets'
|
153
|
-
|
154
|
-
|
155
|
-
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
156
|
-
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
157
|
-
|
158
|
-
pp binary == hex
|
159
|
-
# => true
|
160
|
-
|
161
|
-
str = "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee".gsub( ' ', '' )
|
162
|
-
|
163
|
-
str2 = Crockford.encode( hex ) ## (binary) number to text
|
164
|
-
pp str2
|
165
|
-
# => "9999677411e19fee05506644d8681330555665539899beee"
|
166
|
-
pp str == str2
|
167
|
-
# => true
|
168
|
-
pp Crockford.fmt( str2 )
|
169
|
-
# => "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee"
|
170
|
-
|
171
|
-
hex2 = Crockford.decode( str2 ) ## text to (binary) number
|
172
|
-
pp hex
|
173
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
174
|
-
pp hex2
|
175
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
176
|
-
pp hex == hex2
|
177
|
-
# => true
|
178
|
-
```
|
179
|
-
|
180
|
-
or
|
181
|
-
|
182
|
-
|
183
|
-
``` ruby
|
184
|
-
Base32.format = :crockford
|
185
|
-
|
186
|
-
str = Base32.encode( hex ) ## (binary) number to text
|
187
|
-
pp str
|
188
|
-
# => "9999677411e19fee05506644d8681330555665539899beee"
|
189
|
-
pp Base32.fmt( str )
|
190
|
-
# => "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee"
|
191
|
-
pp = Base32.decode( str ) ## text to (binary) number
|
192
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
193
|
-
```
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
## Electrologica
|
198
|
-
|
199
|
-
The electrologica notation / alphabet (
|
200
|
-
`00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31`)
|
201
|
-
|
202
|
-
|
203
|
-
### Electrologica (Base32) Notation
|
204
|
-
|
205
|
-
|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|
|
206
|
-
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
207
|
-
| **00** | 00000 |
|
208
|
-
| **01** | 00001 |
|
209
|
-
| **02** | 00010 |
|
210
|
-
| **03** | 00011 |
|
211
|
-
| **04** | 00100 |
|
212
|
-
| **05** | 00101 |
|
213
|
-
| **06** | 00110 |
|
214
|
-
| **07** | 00111 |
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
### Usage - Encode / Decode
|
219
|
-
|
220
|
-
``` ruby
|
221
|
-
require 'base32-alphabets'
|
222
|
-
|
223
|
-
|
224
|
-
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
225
|
-
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
226
|
-
|
227
|
-
pp binary == hex
|
228
|
-
# => true
|
229
|
-
|
230
|
-
str = "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14".gsub( ' ', '-' )
|
231
|
-
|
232
|
-
str2 = Electrologica.encode( hex ) ## (binary) number to text
|
233
|
-
pp str2
|
234
|
-
# => "09-09-09-09-06-07-07-04-01-01-14-01-09-15-14-14-00-05-05-00-06-06-04-04-13-08-06-08-01-03-03-00-05-05-05-06-06-05-05-03-09-08-09-09-11-14-14-14"
|
235
|
-
pp str == str2
|
236
|
-
# => true
|
237
|
-
pp Electrologica.fmt( str2 )
|
238
|
-
# => "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14"
|
239
|
-
|
240
|
-
hex2 = Electrologica.decode( str2 ) ## text to (binary) number
|
241
|
-
pp hex
|
242
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
243
|
-
pp hex2
|
244
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
245
|
-
pp hex == hex2
|
246
|
-
# => true
|
247
|
-
```
|
248
|
-
|
249
|
-
or
|
250
|
-
|
251
|
-
|
252
|
-
``` ruby
|
253
|
-
Base32.format = :electrologica
|
254
|
-
|
255
|
-
str = Base32.encode( hex ) ## (binary) number to text
|
256
|
-
pp str
|
257
|
-
# => "09-09-09-09-06-07-07-04-01-01-14-01-09-15-14-14-00-05-05-00-06-06-04-04-13-08-06-08-01-03-03-00-05-05-05-06-06-05-05-03-09-08-09-09-11-14-14-14"
|
258
|
-
pp Base32.fmt( str )
|
259
|
-
# => "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14"
|
260
|
-
pp = Base32.decode( str ) ## text to (binary) number
|
261
|
-
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
262
|
-
```
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
## Real World Usage
|
267
|
-
|
268
|
-
See [copycats command line tool (and core library)(https://github.com/cryptocopycats/copycats) - crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain - no ether / gas required
|
269
|
-
|
270
|
-
|
271
|
-
## More Documentation / Articles / Samples
|
272
|
-
|
273
|
-
- [Programming Crypto Collectibles Step-by-Step Book / Guide](https://github.com/cryptocopycats/programming-cryptocollectibles)
|
274
|
-
Let's start with CryptoKitties & Copycats. Inside Unique Bits & Bytes on the Blockchain...
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
The `base32-alphabets` scripts are dedicated to the public domain.
|
287
|
-
Use it as you please with no restrictions whatsoever.
|
1
|
+
# Base32 Encoding / Decoding - 5-Bit Notations / Alphabets - Kai / Crockford / Electrologica
|
2
|
+
|
3
|
+
|
4
|
+
Encode / decode numbers in 5-bit groups (2^5=32)
|
5
|
+
with Kai, Crockford or Electrologica notation / alphabet
|
6
|
+
|
7
|
+
|
8
|
+
* home :: [github.com/rubycoco/blockchain](https://github.com/rubycoco/blockchain)
|
9
|
+
* bugs :: [github.com/rubycoco/blockchain/issues](https://github.com/rubycoco/blockchain/issues)
|
10
|
+
* gem :: [rubygems.org/gems/base32-alphabets](https://rubygems.org/gems/base32-alphabets)
|
11
|
+
* rdoc :: [rubydoc.info/gems/base32-alphabets](http://rubydoc.info/gems/base32-alphabets)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
[Kai](#kai) •
|
17
|
+
[Crockford](#crockford) •
|
18
|
+
[Electrologica](#electrologica)
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
## Kai
|
24
|
+
|
25
|
+
The kai notation / alphabet (`123456789abcdefghijkmnopqrstuvwx`)
|
26
|
+
|
27
|
+
Note: Following base56 - the digit-0 and the letter-l
|
28
|
+
are NOT used in the kai alphabet / notation.
|
29
|
+
|
30
|
+
### Kai (Base32) Notation
|
31
|
+
|
32
|
+
|Kai |Binary |Num|Kai |Binary |Num|Kai |Binary |Num|Kai |Binary |Num|
|
33
|
+
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
34
|
+
| **1** | 00000 | 0 | **9** | 01000 | 8 | **h** | 10000 |16 | **q** | 11000 |24 |
|
35
|
+
| **2** | 00001 | 1 | **a** | 01001 | 9 | **i** | 10001 |17 | **r** | 11001 |25 |
|
36
|
+
| **3** | 00010 | 2 | **b** | 01010 | 10 | **j** | 10010 |18 | **s** | 11010 |26 |
|
37
|
+
| **4** | 00011 | 3 | **c** | 01011 | 11 | **k** | 10011 |19 | **t** | 11011 |27 |
|
38
|
+
| **5** | 00100 | 4 | **d** | 01100 | 12 | **m** | 10100 |20 | **u** | 11100 |28 |
|
39
|
+
| **6** | 00101 | 5 | **e** | 01101 | 13 | **n** | 10101 |21 | **v** | 11101 |29 |
|
40
|
+
| **7** | 00110 | 6 | **f** | 01110 | 14 | **o** | 10110 |22 | **w** | 11110 |30 |
|
41
|
+
| **8** | 00111 | 7 | **g** | 01111 | 15 | **p** | 10111 |23 | **x** | 11111 |31 |
|
42
|
+
|
43
|
+
Note: The digit-0 and the letter-l are NOT used in kai.
|
44
|
+
|
45
|
+
|
46
|
+
### Usage - Encode / Decode
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
require 'base32-alphabets'
|
50
|
+
|
51
|
+
|
52
|
+
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
53
|
+
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
54
|
+
|
55
|
+
pp binary == hex
|
56
|
+
# => true
|
57
|
+
|
58
|
+
str = "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff".gsub( ' ', '' )
|
59
|
+
|
60
|
+
str2 = Kai.encode( hex ) ## (binary) number to text
|
61
|
+
pp str
|
62
|
+
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
63
|
+
pp str2
|
64
|
+
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
65
|
+
pp str == str2
|
66
|
+
# => true
|
67
|
+
pp Kai.fmt( str2 )
|
68
|
+
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
69
|
+
pp Kai.fmt( hex ) # all-in-one "shortcut" for Kai.fmt( Kai.encode( hex ))
|
70
|
+
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
71
|
+
|
72
|
+
hex2 = Kai.decode( str2 ) ## text to (binary) number
|
73
|
+
pp hex
|
74
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
75
|
+
pp hex2
|
76
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
77
|
+
pp hex == hex2
|
78
|
+
# => true
|
79
|
+
|
80
|
+
pp = Kai.bytes( hex )
|
81
|
+
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
82
|
+
pp = Kai.bytes( str ) # or from a kai string (auto-decodes to hex first)
|
83
|
+
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
84
|
+
```
|
85
|
+
|
86
|
+
or
|
87
|
+
|
88
|
+
|
89
|
+
``` ruby
|
90
|
+
Base32.format = :kai
|
91
|
+
|
92
|
+
str = Base32.encode( hex ) ## (binary) number to text
|
93
|
+
pp str
|
94
|
+
# => "aaaa788522f2agff16617755e979244166677664a9aacfff"
|
95
|
+
pp Base32.fmt( str )
|
96
|
+
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
97
|
+
pp Base32.fmt( hex ) # all-in-one "shortcut" for Base32.fmt( Base32.encode( hex ))
|
98
|
+
# => "aaaa 7885 22f2 agff 1661 7755 e979 2441 6667 7664 a9aa cfff"
|
99
|
+
pp = Base32.decode( str ) ## text to (binary) number
|
100
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
101
|
+
pp = Base32.bytes( hex )
|
102
|
+
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
103
|
+
pp = Base32.bytes( str ) # or from a kai string (auto-decodes to hex first)
|
104
|
+
# => [9,9,9,9,6,7,7,4,1,1,14,1,9,15,14,14,0,5,5,0,6,6,4,4,13,8,6,8,1,3,3,0,5,5,5,6,6,5,5,3,9,8,9,9,11,14,14,14]
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
### Why Kai?
|
109
|
+
|
110
|
+
The Kai notation / alphabet is named in honor of Kai Turner
|
111
|
+
who first deciphered the CryptoKitties 256-bit genes in 5-bit groups - thanks!
|
112
|
+
See [The CryptoKitties Genome Project: On Dominance, Inheritance and Mutation](https://medium.com/@kaigani/the-cryptokitties-genome-project-on-dominance-inheritance-and-mutation-b73059dcd0a4), January 2018.
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
## Crockford
|
120
|
+
|
121
|
+
The crockford notation / alphabet (`0123456789abcdefghjkmnpqrstvwxyz`)
|
122
|
+
|
123
|
+
Note: The Crockford Base32 symbol set is a superset of the Base16 (hexadecimal) symbol set
|
124
|
+
and starts counting at zero (0).
|
125
|
+
|
126
|
+
|
127
|
+
### Crockford (Base32) Notation
|
128
|
+
|
129
|
+
|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|
|
130
|
+
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
131
|
+
| **0** | 00000 | 0 | **8** | 01000 | 8 | **g** | 10000 |16 | **r** | 11000 |24 |
|
132
|
+
| **1** | 00001 | 1 | **9** | 01001 | 9 | **h** | 10001 |17 | **s** | 11001 |25 |
|
133
|
+
| **2** | 00010 | 2 | **a** | 01010 | 10 | **j** | 10010 |18 | **t** | 11010 |26 |
|
134
|
+
| **3** | 00011 | 3 | **b** | 01011 | 11 | **k** | 10011 |19 | **v** | 11011 |27 |
|
135
|
+
| **4** | 00100 | 4 | **c** | 01100 | 12 | **m** | 10100 |20 | **w** | 11100 |28 |
|
136
|
+
| **5** | 00101 | 5 | **d** | 01101 | 13 | **n** | 10101 |21 | **x** | 11101 |29 |
|
137
|
+
| **6** | 00110 | 6 | **e** | 01110 | 14 | **p** | 10110 |22 | **y** | 11110 |30 |
|
138
|
+
| **7** | 00111 | 7 | **f** | 01111 | 15 | **q** | 10111 |23 | **z** | 11111 |31 |
|
139
|
+
|
140
|
+
Note: 4 of the 26 letters are excluded: I L O U.
|
141
|
+
|
142
|
+
- I Can be confused with 1
|
143
|
+
- L Can be confused with 1
|
144
|
+
- O Can be confused with 0
|
145
|
+
- U Accidental obscenity
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
### Usage - Encode / Decode
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
require 'base32-alphabets'
|
153
|
+
|
154
|
+
|
155
|
+
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
156
|
+
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
157
|
+
|
158
|
+
pp binary == hex
|
159
|
+
# => true
|
160
|
+
|
161
|
+
str = "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee".gsub( ' ', '' )
|
162
|
+
|
163
|
+
str2 = Crockford.encode( hex ) ## (binary) number to text
|
164
|
+
pp str2
|
165
|
+
# => "9999677411e19fee05506644d8681330555665539899beee"
|
166
|
+
pp str == str2
|
167
|
+
# => true
|
168
|
+
pp Crockford.fmt( str2 )
|
169
|
+
# => "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee"
|
170
|
+
|
171
|
+
hex2 = Crockford.decode( str2 ) ## text to (binary) number
|
172
|
+
pp hex
|
173
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
174
|
+
pp hex2
|
175
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
176
|
+
pp hex == hex2
|
177
|
+
# => true
|
178
|
+
```
|
179
|
+
|
180
|
+
or
|
181
|
+
|
182
|
+
|
183
|
+
``` ruby
|
184
|
+
Base32.format = :crockford
|
185
|
+
|
186
|
+
str = Base32.encode( hex ) ## (binary) number to text
|
187
|
+
pp str
|
188
|
+
# => "9999677411e19fee05506644d8681330555665539899beee"
|
189
|
+
pp Base32.fmt( str )
|
190
|
+
# => "9999 6774 11e1 9fee 0550 6644 d868 1330 5556 6553 9899 beee"
|
191
|
+
pp = Base32.decode( str ) ## text to (binary) number
|
192
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
## Electrologica
|
198
|
+
|
199
|
+
The electrologica notation / alphabet (
|
200
|
+
`00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31`)
|
201
|
+
|
202
|
+
|
203
|
+
### Electrologica (Base32) Notation
|
204
|
+
|
205
|
+
|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|Base32 |Binary |Num|
|
206
|
+
|------:|------:|--:|------:|------:|--:|------:|------:|--:|------:|------:|--:|
|
207
|
+
| **00** | 00000 | 0 | **08** | 01000 | 8 | **16** | 10000 |16 | **24** | 11000 |24 |
|
208
|
+
| **01** | 00001 | 1 | **09** | 01001 | 9 | **17** | 10001 |17 | **25** | 11001 |25 |
|
209
|
+
| **02** | 00010 | 2 | **10** | 01010 | 10 | **18** | 10010 |18 | **26** | 11010 |26 |
|
210
|
+
| **03** | 00011 | 3 | **11** | 01011 | 11 | **19** | 10011 |19 | **27** | 11011 |27 |
|
211
|
+
| **04** | 00100 | 4 | **12** | 01100 | 12 | **20** | 10100 |20 | **28** | 11100 |28 |
|
212
|
+
| **05** | 00101 | 5 | **13** | 01101 | 13 | **21** | 10101 |21 | **29** | 11101 |29 |
|
213
|
+
| **06** | 00110 | 6 | **14** | 01110 | 14 | **22** | 10110 |22 | **30** | 11110 |30 |
|
214
|
+
| **07** | 00111 | 7 | **15** | 01111 | 15 | **23** | 10111 |23 | **31** | 11111 |31 |
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
### Usage - Encode / Decode
|
219
|
+
|
220
|
+
``` ruby
|
221
|
+
require 'base32-alphabets'
|
222
|
+
|
223
|
+
|
224
|
+
binary = 0b0000000000000000010010100101001010010011000111001110010000001000010111000001010010111101110011100000000101001010000000110001100010000100011010100000110010000000100011000110000000101001010010100110001100010100101000110100101000010010100101011011100111001110 # binary
|
225
|
+
hex = 0x00004a52931ce4085c14bdce014a0318846a0c808c60294a6314a34a1295b9ce # hex
|
226
|
+
|
227
|
+
pp binary == hex
|
228
|
+
# => true
|
229
|
+
|
230
|
+
str = "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14".gsub( ' ', '-' )
|
231
|
+
|
232
|
+
str2 = Electrologica.encode( hex ) ## (binary) number to text
|
233
|
+
pp str2
|
234
|
+
# => "09-09-09-09-06-07-07-04-01-01-14-01-09-15-14-14-00-05-05-00-06-06-04-04-13-08-06-08-01-03-03-00-05-05-05-06-06-05-05-03-09-08-09-09-11-14-14-14"
|
235
|
+
pp str == str2
|
236
|
+
# => true
|
237
|
+
pp Electrologica.fmt( str2 )
|
238
|
+
# => "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14"
|
239
|
+
|
240
|
+
hex2 = Electrologica.decode( str2 ) ## text to (binary) number
|
241
|
+
pp hex
|
242
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
243
|
+
pp hex2
|
244
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
245
|
+
pp hex == hex2
|
246
|
+
# => true
|
247
|
+
```
|
248
|
+
|
249
|
+
or
|
250
|
+
|
251
|
+
|
252
|
+
``` ruby
|
253
|
+
Base32.format = :electrologica
|
254
|
+
|
255
|
+
str = Base32.encode( hex ) ## (binary) number to text
|
256
|
+
pp str
|
257
|
+
# => "09-09-09-09-06-07-07-04-01-01-14-01-09-15-14-14-00-05-05-00-06-06-04-04-13-08-06-08-01-03-03-00-05-05-05-06-06-05-05-03-09-08-09-09-11-14-14-14"
|
258
|
+
pp Base32.fmt( str )
|
259
|
+
# => "09-09-09-09 06-07-07-04 01-01-14-01 09-15-14-14 00-05-05-00 06-06-04-04 13-08-06-08 01-03-03-00 05-05-05-06 06-05-05-03 09-08-09-09 11-14-14-14"
|
260
|
+
pp = Base32.decode( str ) ## text to (binary) number
|
261
|
+
# => 512955438081049600613224346938352058409509756310147795204209859701881294
|
262
|
+
```
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
## Real World Usage
|
267
|
+
|
268
|
+
See the [copycats command line tool (and core library)](https://github.com/cryptocopycats/copycats) - crypto cats / kitties collectibles unchained - buy! sell! hodl! sire! - play for free - runs off the blockchain - no ether / gas required
|
269
|
+
|
270
|
+
|
271
|
+
## More Documentation / Articles / Samples
|
272
|
+
|
273
|
+
- [Programming Crypto Collectibles Step-by-Step Book / Guide](https://github.com/cryptocopycats/programming-cryptocollectibles) -
|
274
|
+
Let's start with CryptoKitties & Copycats. Inside Unique Bits & Bytes on the Blockchain...
|
275
|
+
- [Ruby Quiz - Challenge #8 - Base32 Alphabet](https://github.com/planetruby/quiz/tree/master/008) - Convert the Super "Sekretoooo" 256-Bit CryptoKitties Genome to Kai Notation - Annipurrsary!
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
## License
|
282
|
+
|
283
|
+
The `base32-alphabets` scripts are dedicated to the public domain.
|
284
|
+
Use it as you please with no restrictions whatsoever.
|
data/Rakefile
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'hoe'
|
2
|
-
require './lib/base32-alphabets/version.rb'
|
3
|
-
|
4
|
-
Hoe.spec 'base32-alphabets' do
|
5
|
-
|
6
|
-
self.version = Base32::VERSION
|
7
|
-
|
8
|
-
self.summary = "base32-alphabets - base32 (2^5) encoding / decoding in 5-bit groups with kai, crockford or electrologica notation / alphabet"
|
9
|
-
self.description = summary
|
10
|
-
|
11
|
-
self.urls =
|
12
|
-
|
13
|
-
self.author = 'Gerald Bauer'
|
14
|
-
self.email = 'wwwmake@googlegroups.com'
|
15
|
-
|
16
|
-
# switch extension to .markdown for gihub formatting
|
17
|
-
self.readme_file = 'README.md'
|
18
|
-
self.history_file = 'CHANGELOG.md'
|
19
|
-
|
20
|
-
self.extra_deps = [
|
21
|
-
]
|
22
|
-
|
23
|
-
self.licenses = ['Public Domain']
|
24
|
-
|
25
|
-
self.spec_extras = {
|
26
|
-
required_ruby_version: '>= 2.3'
|
27
|
-
}
|
28
|
-
|
29
|
-
end
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/base32-alphabets/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'base32-alphabets' do
|
5
|
+
|
6
|
+
self.version = Base32::VERSION
|
7
|
+
|
8
|
+
self.summary = "base32-alphabets - base32 (2^5) encoding / decoding in 5-bit groups with kai, crockford or electrologica notation / alphabet"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = { home: 'https://github.com/rubycoco/blockchain' }
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'wwwmake@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
]
|
22
|
+
|
23
|
+
self.licenses = ['Public Domain']
|
24
|
+
|
25
|
+
self.spec_extras = {
|
26
|
+
required_ruby_version: '>= 2.3'
|
27
|
+
}
|
28
|
+
|
29
|
+
end
|
data/lib/base32-alphabets.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
|
6
|
-
## our own code
|
7
|
-
require 'base32-alphabets/version' # note: let version always go first
|
8
|
-
|
9
|
-
require 'base32-alphabets/base'
|
10
|
-
require 'base32-alphabets/kai'
|
11
|
-
require 'base32-alphabets/crockford'
|
12
|
-
require 'base32-alphabets/electrologica'
|
13
|
-
require 'base32-alphabets/base32'
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
## add a shortcut (convenience) alias
|
20
|
-
Kai = Base32::Kai
|
21
|
-
Crockford = Base32::Crockford
|
22
|
-
Electrologica = Base32::Electrologica
|
23
|
-
|
24
|
-
|
25
|
-
def encode32( num_or_bytes )
|
26
|
-
Base32.encode( num_or_bytes )
|
27
|
-
end
|
28
|
-
|
29
|
-
def decode32( str_or_bytes )
|
30
|
-
Base32.decode( str_or_bytes )
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
## -- add bytes32 - why? why not?
|
35
|
-
##
|
36
|
-
## def bytes32( num_or_str )
|
37
|
-
## Base32.bytes( num_or_str )
|
38
|
-
## end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# say hello
|
43
|
-
puts Base32.banner if $DEBUG || (defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG)
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
|
6
|
+
## our own code
|
7
|
+
require 'base32-alphabets/version' # note: let version always go first
|
8
|
+
|
9
|
+
require 'base32-alphabets/base'
|
10
|
+
require 'base32-alphabets/kai'
|
11
|
+
require 'base32-alphabets/crockford'
|
12
|
+
require 'base32-alphabets/electrologica'
|
13
|
+
require 'base32-alphabets/base32'
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## add a shortcut (convenience) alias
|
20
|
+
Kai = Base32::Kai
|
21
|
+
Crockford = Base32::Crockford
|
22
|
+
Electrologica = Base32::Electrologica
|
23
|
+
|
24
|
+
|
25
|
+
def encode32( num_or_bytes )
|
26
|
+
Base32.encode( num_or_bytes )
|
27
|
+
end
|
28
|
+
|
29
|
+
def decode32( str_or_bytes )
|
30
|
+
Base32.decode( str_or_bytes )
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
## -- add bytes32 - why? why not?
|
35
|
+
##
|
36
|
+
## def bytes32( num_or_str )
|
37
|
+
## Base32.bytes( num_or_str )
|
38
|
+
## end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
# say hello
|
43
|
+
puts Base32.banner if $DEBUG || (defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG)
|
@@ -1,23 +1,21 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Base32
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end # module Base32
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Base32
|
4
|
+
MAJOR = 1
|
5
|
+
MINOR = 2
|
6
|
+
PATCH = 0
|
7
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
|
+
|
9
|
+
def self.version
|
10
|
+
VERSION
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"base32-alphabets/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.root
|
18
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
19
|
+
end
|
20
|
+
|
21
|
+
end # module Base32
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
## $:.unshift(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
## minitest setup
|
4
|
-
|
5
|
-
require 'minitest/autorun'
|
6
|
-
|
7
|
-
|
8
|
-
## our own code
|
9
|
-
|
10
|
-
require 'base32-alphabets'
|
1
|
+
## $:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
## minitest setup
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
|
8
|
+
## our own code
|
9
|
+
|
10
|
+
require 'base32-alphabets'
|
@@ -1,56 +1,56 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_base32_crockford.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
|
11
|
-
class TestBase32Crockford < MiniTest::Test
|
12
|
-
|
13
|
-
def test_encoding_and_decoding_single_chars
|
14
|
-
from = (0..31).to_a
|
15
|
-
to = %w[ 0 1 2 3 4 5 6 7 8 9 a b c d e f g h j k m n p q r s t v w x y z]
|
16
|
-
|
17
|
-
from.zip(to) do |symbol_value, encode_symbol|
|
18
|
-
assert_equal encode_symbol, Base32::Crockford.encode( symbol_value )
|
19
|
-
assert_equal symbol_value, Base32::Crockford.decode( encode_symbol )
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_encoding_larger_numbers
|
24
|
-
assert_equal '10', Base32::Crockford.encode( 32 )
|
25
|
-
assert_equal '16j', Base32::Crockford.encode( 1234 )
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_decoding_strings
|
29
|
-
assert_equal 1234, Base32::Crockford.decode( '16j' )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_decoding_normalizes_symbols
|
33
|
-
assert_equal Base32::Crockford.decode('11100110'),
|
34
|
-
Base32::Crockford.decode('IL1O0ilo')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_decoding_lowercase
|
38
|
-
assert_equal Base32::Crockford.decode('abcdefghijklmnopqrstvwxyz'),
|
39
|
-
Base32::Crockford.decode('ABCDEFGHIJKLMNOPQRSTVWXYZ')
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_decode_should_ignore_hyphens
|
43
|
-
assert_equal 1234, Base32::Crockford.decode('1-6-j')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_decoding_invalid_strings
|
47
|
-
assert_raises(ArgumentError) { Base32::Crockford.decode("'+?") }
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_group_and_hyphens
|
51
|
-
assert_equal "16j", Base32::Crockford.fmt( 1234, group: 5)
|
52
|
-
assert_equal "1-6j", Base32::Crockford.fmt( 1234, group: 2, sep: '-')
|
53
|
-
assert_equal "10", Base32::Crockford.fmt( 32, group: 3)
|
54
|
-
end
|
55
|
-
|
56
|
-
end # class TestBase32Crockford
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_base32_crockford.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestBase32Crockford < MiniTest::Test
|
12
|
+
|
13
|
+
def test_encoding_and_decoding_single_chars
|
14
|
+
from = (0..31).to_a
|
15
|
+
to = %w[ 0 1 2 3 4 5 6 7 8 9 a b c d e f g h j k m n p q r s t v w x y z]
|
16
|
+
|
17
|
+
from.zip(to) do |symbol_value, encode_symbol|
|
18
|
+
assert_equal encode_symbol, Base32::Crockford.encode( symbol_value )
|
19
|
+
assert_equal symbol_value, Base32::Crockford.decode( encode_symbol )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_encoding_larger_numbers
|
24
|
+
assert_equal '10', Base32::Crockford.encode( 32 )
|
25
|
+
assert_equal '16j', Base32::Crockford.encode( 1234 )
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_decoding_strings
|
29
|
+
assert_equal 1234, Base32::Crockford.decode( '16j' )
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_decoding_normalizes_symbols
|
33
|
+
assert_equal Base32::Crockford.decode('11100110'),
|
34
|
+
Base32::Crockford.decode('IL1O0ilo')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_decoding_lowercase
|
38
|
+
assert_equal Base32::Crockford.decode('abcdefghijklmnopqrstvwxyz'),
|
39
|
+
Base32::Crockford.decode('ABCDEFGHIJKLMNOPQRSTVWXYZ')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_decode_should_ignore_hyphens
|
43
|
+
assert_equal 1234, Base32::Crockford.decode('1-6-j')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_decoding_invalid_strings
|
47
|
+
assert_raises(ArgumentError) { Base32::Crockford.decode("'+?") }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_group_and_hyphens
|
51
|
+
assert_equal "16j", Base32::Crockford.fmt( 1234, group: 5)
|
52
|
+
assert_equal "1-6j", Base32::Crockford.fmt( 1234, group: 2, sep: '-')
|
53
|
+
assert_equal "10", Base32::Crockford.fmt( 32, group: 3)
|
54
|
+
end
|
55
|
+
|
56
|
+
end # class TestBase32Crockford
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base32-alphabets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: hoe
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
39
|
+
version: '3.22'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
46
|
+
version: '3.22'
|
41
47
|
description: base32-alphabets - base32 (2^5) encoding / decoding in 5-bit groups with
|
42
48
|
kai, crockford or electrologica notation / alphabet
|
43
49
|
email: wwwmake@googlegroups.com
|
@@ -45,12 +51,10 @@ executables: []
|
|
45
51
|
extensions: []
|
46
52
|
extra_rdoc_files:
|
47
53
|
- CHANGELOG.md
|
48
|
-
- LICENSE.md
|
49
54
|
- Manifest.txt
|
50
55
|
- README.md
|
51
56
|
files:
|
52
57
|
- CHANGELOG.md
|
53
|
-
- LICENSE.md
|
54
58
|
- Manifest.txt
|
55
59
|
- README.md
|
56
60
|
- Rakefile
|
@@ -66,11 +70,11 @@ files:
|
|
66
70
|
- test/test_base32_electrologica.rb
|
67
71
|
- test/test_base32_kai.rb
|
68
72
|
- test/test_bytes.rb
|
69
|
-
homepage: https://github.com/
|
73
|
+
homepage: https://github.com/rubycoco/blockchain
|
70
74
|
licenses:
|
71
75
|
- Public Domain
|
72
76
|
metadata: {}
|
73
|
-
post_install_message:
|
77
|
+
post_install_message:
|
74
78
|
rdoc_options:
|
75
79
|
- "--main"
|
76
80
|
- README.md
|
@@ -87,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
91
|
- !ruby/object:Gem::Version
|
88
92
|
version: '0'
|
89
93
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
signing_key:
|
94
|
+
rubygems_version: 3.1.4
|
95
|
+
signing_key:
|
93
96
|
specification_version: 4
|
94
97
|
summary: base32-alphabets - base32 (2^5) encoding / decoding in 5-bit groups with
|
95
98
|
kai, crockford or electrologica notation / alphabet
|
data/LICENSE.md
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
CC0 1.0 Universal
|
2
|
-
|
3
|
-
Statement of Purpose
|
4
|
-
|
5
|
-
The laws of most jurisdictions throughout the world automatically confer
|
6
|
-
exclusive Copyright and Related Rights (defined below) upon the creator and
|
7
|
-
subsequent owner(s) (each and all, an "owner") of an original work of
|
8
|
-
authorship and/or a database (each, a "Work").
|
9
|
-
|
10
|
-
Certain owners wish to permanently relinquish those rights to a Work for the
|
11
|
-
purpose of contributing to a commons of creative, cultural and scientific
|
12
|
-
works ("Commons") that the public can reliably and without fear of later
|
13
|
-
claims of infringement build upon, modify, incorporate in other works, reuse
|
14
|
-
and redistribute as freely as possible in any form whatsoever and for any
|
15
|
-
purposes, including without limitation commercial purposes. These owners may
|
16
|
-
contribute to the Commons to promote the ideal of a free culture and the
|
17
|
-
further production of creative, cultural and scientific works, or to gain
|
18
|
-
reputation or greater distribution for their Work in part through the use and
|
19
|
-
efforts of others.
|
20
|
-
|
21
|
-
For these and/or other purposes and motivations, and without any expectation
|
22
|
-
of additional consideration or compensation, the person associating CC0 with a
|
23
|
-
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
24
|
-
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
25
|
-
and publicly distribute the Work under its terms, with knowledge of his or her
|
26
|
-
Copyright and Related Rights in the Work and the meaning and intended legal
|
27
|
-
effect of CC0 on those rights.
|
28
|
-
|
29
|
-
1. Copyright and Related Rights. A Work made available under CC0 may be
|
30
|
-
protected by copyright and related or neighboring rights ("Copyright and
|
31
|
-
Related Rights"). Copyright and Related Rights include, but are not limited
|
32
|
-
to, the following:
|
33
|
-
|
34
|
-
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
35
|
-
and translate a Work;
|
36
|
-
|
37
|
-
ii. moral rights retained by the original author(s) and/or performer(s);
|
38
|
-
|
39
|
-
iii. publicity and privacy rights pertaining to a person's image or likeness
|
40
|
-
depicted in a Work;
|
41
|
-
|
42
|
-
iv. rights protecting against unfair competition in regards to a Work,
|
43
|
-
subject to the limitations in paragraph 4(a), below;
|
44
|
-
|
45
|
-
v. rights protecting the extraction, dissemination, use and reuse of data in
|
46
|
-
a Work;
|
47
|
-
|
48
|
-
vi. database rights (such as those arising under Directive 96/9/EC of the
|
49
|
-
European Parliament and of the Council of 11 March 1996 on the legal
|
50
|
-
protection of databases, and under any national implementation thereof,
|
51
|
-
including any amended or successor version of such directive); and
|
52
|
-
|
53
|
-
vii. other similar, equivalent or corresponding rights throughout the world
|
54
|
-
based on applicable law or treaty, and any national implementations thereof.
|
55
|
-
|
56
|
-
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
57
|
-
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
58
|
-
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
59
|
-
and Related Rights and associated claims and causes of action, whether now
|
60
|
-
known or unknown (including existing as well as future claims and causes of
|
61
|
-
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
62
|
-
duration provided by applicable law or treaty (including future time
|
63
|
-
extensions), (iii) in any current or future medium and for any number of
|
64
|
-
copies, and (iv) for any purpose whatsoever, including without limitation
|
65
|
-
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
66
|
-
the Waiver for the benefit of each member of the public at large and to the
|
67
|
-
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
68
|
-
shall not be subject to revocation, rescission, cancellation, termination, or
|
69
|
-
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
70
|
-
by the public as contemplated by Affirmer's express Statement of Purpose.
|
71
|
-
|
72
|
-
3. Public License Fallback. Should any part of the Waiver for any reason be
|
73
|
-
judged legally invalid or ineffective under applicable law, then the Waiver
|
74
|
-
shall be preserved to the maximum extent permitted taking into account
|
75
|
-
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
76
|
-
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
77
|
-
non transferable, non sublicensable, non exclusive, irrevocable and
|
78
|
-
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
79
|
-
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
80
|
-
provided by applicable law or treaty (including future time extensions), (iii)
|
81
|
-
in any current or future medium and for any number of copies, and (iv) for any
|
82
|
-
purpose whatsoever, including without limitation commercial, advertising or
|
83
|
-
promotional purposes (the "License"). The License shall be deemed effective as
|
84
|
-
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
85
|
-
License for any reason be judged legally invalid or ineffective under
|
86
|
-
applicable law, such partial invalidity or ineffectiveness shall not
|
87
|
-
invalidate the remainder of the License, and in such case Affirmer hereby
|
88
|
-
affirms that he or she will not (i) exercise any of his or her remaining
|
89
|
-
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
90
|
-
and causes of action with respect to the Work, in either case contrary to
|
91
|
-
Affirmer's express Statement of Purpose.
|
92
|
-
|
93
|
-
4. Limitations and Disclaimers.
|
94
|
-
|
95
|
-
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
96
|
-
surrendered, licensed or otherwise affected by this document.
|
97
|
-
|
98
|
-
b. Affirmer offers the Work as-is and makes no representations or warranties
|
99
|
-
of any kind concerning the Work, express, implied, statutory or otherwise,
|
100
|
-
including without limitation warranties of title, merchantability, fitness
|
101
|
-
for a particular purpose, non infringement, or the absence of latent or
|
102
|
-
other defects, accuracy, or the present or absence of errors, whether or not
|
103
|
-
discoverable, all to the greatest extent permissible under applicable law.
|
104
|
-
|
105
|
-
c. Affirmer disclaims responsibility for clearing rights of other persons
|
106
|
-
that may apply to the Work or any use thereof, including without limitation
|
107
|
-
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
108
|
-
disclaims responsibility for obtaining any necessary consents, permissions
|
109
|
-
or other rights required for any use of the Work.
|
110
|
-
|
111
|
-
d. Affirmer understands and acknowledges that Creative Commons is not a
|
112
|
-
party to this document and has no duty or obligation with respect to this
|
113
|
-
CC0 or use of the Work.
|
114
|
-
|
115
|
-
For more information, please see
|
116
|
-
<http://creativecommons.org/publicdomain/zero/1.0/>
|