Base32
1 API
1.1 Encoding and decoding byte-strings
base32?
base32-decode-bytes
base32-encode-bytes
1.2 Encoding and decoding ports
base32-decode
base32-encode
1.3 Comparing base32 strings
base32=?
base32<?
2 Conversion table
7.7

Base32

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:

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.

1 API

 (require base32) package: base32

1.1 Encoding and decoding byte-strings

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.2 Encoding and decoding ports

procedure

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

  in : 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?

  in : 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.3 Comparing base32 strings

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

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

#f

> (base32=? x y)

#t

> (string<? x y)

#t

> (base32<? x y)

#f

procedure

(base32=? x y)  boolean?

  x : base32?
  y : base32?
Determine if two base32 strings are equivalent after normalizing synonymous characters.

procedure

(base32<? x y)  boolean?

  x : base32?
  y : base32?
Determine if two base32 strings are ordered lexicographically after normalizing synonymous characters.

2 Conversion table

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