genalphabet.go raw
1 // Copyright (c) 2015 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "bytes"
9 "io"
10 "log"
11 "os"
12 "strconv"
13 )
14
15 var (
16 start = []byte(`// Copyright (c) 2015 The btcsuite developers
17 // Use of this source code is governed by an ISC
18 // license that can be found in the LICENSE file.
19
20 // AUTOGENERATED by genalphabet.go; do not edit.
21
22 package base58
23
24 const (
25 // Ciphers is the modified base58 alphabet used by Bitcoin.
26 Ciphers = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
27
28 alphabetIdx0 = '1'
29 )
30
31 var b58 = [256]byte{`)
32
33 end = []byte(`}`)
34
35 alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
36 tab = []byte("\t")
37 invalid = []byte("255")
38 comma = []byte(",")
39 space = []byte(" ")
40 nl = []byte("\n")
41 )
42
43 func write(w io.Writer, b []byte) {
44 _, err := w.Write(b)
45 if err != nil {
46 log.Fatal(err)
47 }
48 }
49
50 func main() {
51 fi, err := os.Create("alphabet.go")
52 if err != nil {
53 log.Fatal(err)
54 }
55 defer fi.Close()
56
57 write(fi, start)
58 write(fi, nl)
59 for i := byte(0); i < 32; i++ {
60 write(fi, tab)
61 for j := byte(0); j < 8; j++ {
62 idx := bytes.IndexByte(alphabet, i*8+j)
63 if idx == -1 {
64 write(fi, invalid)
65 } else {
66 write(fi, strconv.AppendInt(nil, int64(idx), 10))
67 }
68 write(fi, comma)
69 if j != 7 {
70 write(fi, space)
71 }
72 }
73 write(fi, nl)
74 }
75 write(fi, end)
76 write(fi, nl)
77 }
78