1API
9.0
top
← prev up next →

Base32πŸ”— i

James Alexander Feldman-Crough <alex@fldcr.com>

This library provides utilities for converting byte-strings to and from an encoding based on Crockford’s Base32 encoding.

Compared to similar Base32 encodings like RFC 4648, Crockford’s encoding has a few desirable characteristics which make it especially appealing for user-facing use:

  • Potentially ambiguous characters, like i, I, l, and L are treated as synonyms.

  • The digits 0 through F have the same value as their hexadecimal counterparts.

  • The letter U is invalid, lowering the surface area for obscene encodings.

This library deviates from Crockford’s encoding by encoding strings as lower-case by default. Hyphens are also disallowed as spacing and check characters are unimplemented, although this is a shortcoming of the implementation.

1APIπŸ”— i

(require base32 ) package: base32

1.1Encoding and decoding byte-stringsπŸ”— i

procedure

( base32? x)boolean?

x:any/c
Determines whether or not a value is a valid Base32 encoding.

procedure

( base32-decode-bytes b32)bytes?

b32:base32?
Encodes bs as a base32 encoded string.

procedure

( base32-encode-bytes bs)base32?

bs:bytes?
Encodes bs as a base32 encoded string.

1.2Encoding and decoding portsπŸ”— i

procedure

( base32-decode in[#:close?close?])input-port?

close?:boolean? =#t
Create a new input port that reads bytes from in after decoding them. If in is not base32 encoded, read will raise an exn:fail:contract upon encountering an invalid character.

If close? is #t, in will be closed once eof is reached.

procedure

( base32-encode in[#:close?close?])input-port?

close?:boolean? =#t
Create a new input port that reads base64-encoded bytes from in.

If close? is #t, in will be closed once eof is reached.

1.3Comparing base32 stringsπŸ”— i

Because some characters are synonymous, two Base32 encodings may be representationally equivalent but not structurally equivalent.

Examples:
> (define-values (xy)
(values "ABC0123"
"abcoi23"))
> (equal? xy)

#f

> (base32=? xy)

#t

> (string<? xy)

#t

> (base32<? xy)

#f

procedure

( base32=? xy)boolean?

Determine if two base32 strings are equivalent after normalizing synonymous characters.

procedure

( base32<? xy)boolean?

Determine if two base32 strings are ordered lexicographically after normalizing synonymous characters.

2Conversion tableπŸ”— i

The following table shows the decimal value for each valid base32 character. When encoding, this library always chooses the first base32 representation in the table below.

base 10

base 32

0

0 o O =

1

1 i I l L

2

2

3

3

4

4

5

5

6

6

7

7

8

8

9

9

10

a A

11

b B

12

c C

13

d D

14

e E

15

f F

16

g G

17

h H

18

j J

19

k K

20

m M

21

n N

22

p P

23

q Q

24

r R

25

s S

26

t T

27

v V

28

w W

29

x X

30

y Y

31

z Z

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /