#include <stdio.h>

#define ASCII_NUM	128

static const int b64lookup[ASCII_NUM] = {
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
	52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
	-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
	15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
	-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
	41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
};

int
main()
{
	int i;

	/* Compare the logic of both tables */
	for (i = 0; i < ASCII_NUM; i++)
	{
		char c = i;
		int b_table, b_compare;

		/* method from pgcrypto */
		if (c >= 'A' && c <= 'Z')
			b_compare = c - 'A';
		else if (c >= 'a' && c <= 'z')
			b_compare = c - 'a' + 26;
		else if (c >= '0' && c <= '9')
			b_compare = c - '0' + 52;
		else if (c == '+')
			b_compare = 62;
		else if (c == '/')
			b_compare = 63;
		else
		{
			/*
			 * Can be space, \t, \n, \r or invalid data, who cares.
			 */
			continue;
		}

		/* method from encode.c */
		b_table = -1;
		if (c > 0 && c < 127)
			b_table = b64lookup[c];

		if (b_table != b_compare)
			fprintf(stderr, "Incorrect conversion at char %c\n", c);
	}

	return 0;
}
