Class LuhnCheckDigit

java.lang.Object
org.trustdeck.algorithms.LuhnCheckDigit
Direct Known Subclasses:
LuhnMod10CheckDigit, LuhnMod16CheckDigit, LuhnMod26CheckDigit, LuhnMod32CheckDigit, LuhnMod36CheckDigit, LuhnModNCheckDigit

public abstract class LuhnCheckDigit extends Object
Abstract class that provides the functionalities for calculating a check digit for an arbitrary list of characters as long as the length of this list is divisible by two.
Author:
Armin Müller
  • Constructor Details

    • LuhnCheckDigit

      public LuhnCheckDigit(String allowedCharacters)
      Basic constructor. A list of allowed characters needs to be provided. The list's length must be divisible by two.
      Parameters:
      allowedCharacters -
  • Method Details

    • standardizeInput

      public String standardizeInput(String input, String domainPrefix)
      A method to standardize the input strings (e.g. turns input into upper case, removes domain prefix, ...).
      Parameters:
      input - the unsanitized input string
      domainPrefix - the prefix of the domain where the input is in, including hyphens
      Returns:
      the sanitized input string
    • computeCheckDigit

      public Character computeCheckDigit(String input, String domainPrefix)
      Method to validate the check digit from the given input.
      Parameters:
      input - the unsanitized input string
      domainPrefix - the prefix of the domain where the input should be in, including hyphens
      Returns:
      the check digit for the provided input, null when a character was encountered that is not part of the list of allowed characters
    • validateCheckDigit

      public Boolean validateCheckDigit(String input, String domainPrefix)
      Method to validate the check digit from the given input.
      Parameters:
      input - the unsanitized input string
      domainPrefix - the prefix of the domain where the input is in, including hyphens
      Returns:
      true when the check digit is valid, false when it is invalid, and null when there was a character in the input that is not part of the allowed characters.