Syronex: software solutions

ISBNs & The Modulo 11 Checksum Algorithm

ISBNs are often handled manually and there is therefore a need for a quick way to check whether a particular ISBN is likely to be valid or not. A typical ISBN is represented below, starting with a country code ($c$), followed by a publisher code ($p$) and a title code ($t$). The tenth digit ($\kappa$; called check-digit) depends on all the others. So if there is an alteration in one or more of the first nine digits—and the check-digit is re-calculated, its value is very likely to be different from its original value.

\begin{figure}\begin{center}
{\Large$ \underbrace{\mathtt{0}}_{c} - \underbrace{...
...athtt{88954}}_{t} - \underbrace{\mathtt{4}}_{\kappa} $}
\end{center}\end{figure}

The Checksum Algorithm

  1. [Compute weighted sum.] \( \displaystyle s \leftarrow \sum_{k=1}^{9} (11-k)n_{k}\) where $n_{k}$ is the $k^{th}$ digit in the ISBN.
  2. [Get remainder.] Divide $s$ by 11 and let $r$ be the remainder.
  3. [Find check-digit.]

    1.
    [$r=0$?] If $r=0$, set $\kappa \leftarrow 0$. The algorithm terminates
    2.
    [$r=1$?] If $r=1$, set $\kappa \leftarrow$ `X'. The algorithm terminates.
    3.
    [Else.] If $r>1$, set $\kappa \leftarrow 11-r$. The algorithm terminates. 

Java Implementation

The following program is an implementation in Java of the above algorithm.
public class Mod11Ck {
  public static String calc(String digStr) {
    int len = digStr.length();
    int sum = 0, rem = 0;
    int[] digArr = new int[len];
    for (int k=1; k<=len; k++) // compute weighted sum
      sum += (11 - k) * Character.getNumericValue(digStr.charAt(k - 1));
    if ((rem = sum % 11) == 0) return "0";
    else if (rem == 1) return "X";
    return (new Integer(11 - rem)).toString();
  }
  public static void main(String[] args) {
    System.out.println(args[0]+"-"+calc(args[0]));
  }
}