ChecksumUtility

@interface ChecksumUtility : NSObject

Utility class to check valid checksum. It includes:

  • CRC checksum that is being used in EMVCO standard
  • Luhn checksum that is being used in Mastercard identifier
  • Generate CRC16

    Declaration

    Objective-C

    + (NSString *_Nonnull)crc16:(NSString *_Nonnull)string;

    Swift

    class func crc16(_ string: String) -> String

    Parameters

    string

    String to generate crc for @eturn CRC16 in 4 digit hex code string format with 0 as padding

  • Checks if the qr string includes valid CRC16

    Declaration

    Objective-C

    + (BOOL)isValidCrc16:(NSString *_Nonnull)qrString;

    Swift

    class func isValidCrc16(_ qrString: String) -> Bool

    Parameters

    qrString

    QR code string

    Return Value

    true if the CRC16 in the qrString is valid else false

  • Sum to single digit

    Declaration

    Objective-C

    + (NSInteger)sumToSingleDigit:(NSInteger)digit;

    Swift

    class func sum(toSingleDigit digit: Int) -> Int

    Parameters

    digit

    Digit to sum

    Return Value

    Single digit sum

  • Generate luhn checksum of the string

    Note

    Throw MPQRError.invalidFormat if the the string is not numeric

    Declaration

    Objective-C

    + (NSNumber *_Nullable)luhnChecksum:(NSString *_Nonnull)string
                          hasCheckDigit:(BOOL)hasCheckDigit
                                  error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func luhnChecksum(_ string: String, hasCheckDigit: Bool) throws -> NSNumber

    Parameters

    string

    String to valid luhn checksum for

    hasCheckDigit

    Whether Check digit is already present in the string or not.

    Return Value

    Integer luhn checksum

  • Generate luhn checksum of the string.

    Note

    Throws: MPQRError.invalidFormat if the the string is not numeric

    Note

    Precondition: Check digit should not be present in the string

    Declaration

    Objective-C

    + (NSNumber *_Nullable)luhnChecksum:(NSString *_Nonnull)string
                                  error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func luhnChecksum(_ string: String) throws -> NSNumber

    Parameters

    string

    String to valid luhn checksum for

    Return Value

    Integer luhn checksum

  • Valid luhn checksum of the string

    Note

    Precondition: string should be numeric otherwise this method returns false

    Declaration

    Objective-C

    + (BOOL)validateLuhnChecksum:(NSString *_Nonnull)string;

    Swift

    class func validateLuhnChecksum(_ string: String) -> Bool

    Parameters

    string

    String to valid luhn checksum for

    Return Value

    true if luhn checksum of the string is valid