MCPcopy Create free account
hub / github.com/ZsBT/mrz-java / computeCheckDigit

Method computeCheckDigit

src/main/java/com/innovatrics/mrz/MrzParser.java:241–247  ·  view source on GitHub ↗

Computes MRZ check digit for given string of characters. @param str the string @return check digit in range of 0..9, inclusive. See MRTD documentation part 15 for details.

(String str)

Source from the content-addressed store, hash-verified

239 * @return check digit in range of 0..9, inclusive. See <a href="http://www2.icao.int/en/MRTD/Downloads/Doc%209303/Doc%209303%20English/Doc%209303%20Part%203%20Vol%201.pdf">MRTD documentation</a> part 15 for details.
240 */
241 public static int computeCheckDigit(String str) {
242 int result = 0;
243 for (int i = 0; i < str.length(); i++) {
244 result += getCharacterValue(str.charAt(i)) * MRZ_WEIGHTS[i % MRZ_WEIGHTS.length];
245 }
246 return result % 10;
247 }
248
249 /**
250 * Computes MRZ check digit for given string of characters.

Callers 3

testComputeCheckDigitMethod · 0.95
checkDigitMethod · 0.95
computeCheckDigitCharMethod · 0.95

Calls 2

getCharacterValueMethod · 0.95
lengthMethod · 0.80

Tested by 1

testComputeCheckDigitMethod · 0.76