Here you can find the source of calcChecksum(String value, int length)
public static char calcChecksum(String value, int length)
//package com.java2s; //License from project: Apache License public class Main { public static char calcChecksum(String value, int length) { if (value != null && value.length() == length + 1) { value = value.substring(0, length); }//ww w . j a v a 2s . c o m if (value == null || value.length() != length) { throw new IllegalArgumentException( "Illegal size of value; must be either" + length + " or " + (length + 1) + " characters"); } int oddsum = 0; int evensum = 0; for (int i = value.length() - 1; i >= 0; i--) { if ((value.length() - i) % 2 == 0) { evensum += Character.digit(value.charAt(i), 10); } else { oddsum += Character.digit(value.charAt(i), 10); } } int check = 10 - ((evensum + 3 * oddsum) % 10); if (check >= 10) check = 0; return Character.forDigit(check, 10); } }