blob: faffc87163a5ba40c89a569f53f8a2a47a1cbda3 [file] [log] [blame]
Krzysztof Piotr Oledzki4a3323b2010-01-26 12:32:49 +01001/*
2 * base64rev generator
3 *
4 * Copyright 2009-2010 Krzysztof Piotr Oledzki <ole@ans.pl>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdio.h>
14
15const char base64tab[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
16char base64rev[128];
17
18#define base '#' /* arbitrary chosen base value */
19#define B64MAX 64
20#define B64PADV B64MAX
21
22int main() {
23 char *p, c;
24 int i, min = 255, max = 0;
25
26 for (i = 0; i < sizeof(base64rev); i++)
27 base64rev[i] = base;
28
29 for (i = 0; i < B64MAX; i++) {
30 c = base64tab[i];
31
32 if (min > c)
33 min = c;
34
35 if (max < c)
36 max = c;
37 }
38
39 for (i = 0; i < B64MAX; i++) {
40 c = base64tab[i];
41
42 if (base+i+1 > 127) {
43 printf("Wrong base value @%d\n", i);
44 return 1;
45 }
46
47 base64rev[c - min] = base+i+1;
48 }
49
50 base64rev['=' - min] = base + B64PADV;
51
52 base64rev[max - min + 1] = '\0';
53
54 printf("#define B64BASE '%c'\n", base);
55 printf("#define B64CMIN '%c'\n", min);
56 printf("#define B64CMAX '%c'\n", max);
57 printf("#define B64PADV %u\n", B64PADV);
58
59 p = base64rev;
60 printf("const char base64rev[]=\"");
61 for (p = base64rev; *p; p++) {
62 if (*p == '\\')
63 printf("\\%c", *p);
64 else
65 printf("%c", *p);
66 }
67 printf("\"\n");
68
69 return 0;
70}