import string


__all__ = ["base32"]


class Base32Crockford:
    SYMBOLS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ*~$=U"
    ENCODE_SYMBOLS = {i: ch for (i, ch) in enumerate(SYMBOLS)}
    DECODE_SYMBOLS = {ch: i for (i, ch) in enumerate(SYMBOLS)}
    NORMALIZE_SYMBOLS = string.maketrans("IiLlOo", "111100")

    def encode(self, number, checksum=False):
        """
        """
        if number == 0:
            return '0'

        check_digit = ''
        if checksum:
            check_digit = self.ENCODE_SYMBOLS[number % 37]

        symbol_string = ''
        while number > 0:
            remainder = number % 32
            number /= 32
            symbol_string = self.ENCODE_SYMBOLS[remainder] + symbol_string

        return symbol_string + check_digit

    def decode(self, symbol_string, checksum=False, strict=False):
        """
        """
        symbol_string = self.normalize(symbol_string, strict=strict)
        if checksum:
            symbol_string, check_digit = symbol_string[:-1], symbol_string[-1]

        number = 0
        for char in symbol_string:
            number = number * 32 + self.DECODE_SYMBOLS[char]

        if checksum:
            check_value = self.DECODE_SYMBOLS[check_digit]
            modulo = number % 37
            if check_value != modulo:
                raise ValueError("Invalid checksum digit")

        return number

    def normalize(self, symbol_string, strict=False):
        """
        """
        string = symbol_string.translate(self.NORMALIZE_SYMBOLS, '-').upper()

        if strict and string != symbol_string:
            raise ValueError("Normalization required for string")

        return string


base32 = Base32Crockford()

@@ -347,32 +347,201 @@
 e):%0A        %22%22%22%0A
+        Encodes a base 10 number into a symbol string.%0A%0A        If checksum is set to True, a checksum digit will also be%0A        calculated and appended to the string.%0A
         %22%22%22%0A    
@@ -528,32 +528,32 @@
 ng.%0A        %22%22%22%0A
-
         if numbe
@@ -995,32 +995,409 @@
 e):%0A        %22%22%22%0A
+        Decodes a given symbol string into a base 10 number.%0A%0A        If checksum is set to True, the string is assumed to have a%0A        trailing checksum digit which will be validated. If the%0A        checksum validation fails, a ValueError is raised.%0A%0A        If strict is set to True, a ValueError is raised if the%0A        normalization step requires changes to the string.%0A
         %22%22%22%0A    
@@ -1958,32 +1958,32 @@
  strict=False):%0A
-
         %22%22%22%0A    
@@ -1970,32 +1970,497 @@
 e):%0A        %22%22%22%0A
+        Normalizes a given symbol string to account for error%0A        resistance and prepare it for decoding. These transformations%0A        are applied:%0A%0A           1. Hyphens are removed%0A           2. 'I' or 'i' are converted to '1'%0A           3. 'O' or 'o' are converted to '0'%0A           4. All characters are converted to uppercase%0A%0A        If the strict parameter is set to True, a ValueError is raised%0A        if any of the above transformations are applied.%0A
         %22%22%22%0A    

Add documentation for each class method