CUSIP Checksum Algorithm

Q

What is the CUSIP Checksum Algorithm?

✍: FYIcenter.com

A

The CUSIP Checksum Algorithm is called the Luhn algorithm with "Modulus 10 Double Add Double" technique.

Here is the pseudo code of the CUSIP Checksum Algorithm provided by wikipedia.com:

algorithm Cusip-Check-Digit is
  input: cusip, an 8-character CUSIP.

  sum := 0
  for 0 ≤ i < 8 do
    c := the ith character of cusip
    if c is a digit then
      v := numeric value of the digit c
    else if c is a letter then
      p := ordinal position of c in the alphabet (A=1, B=2...)
      v := p + 9
    else if c = "*" then
      v := 36
    else if c = "@" then
      v := 37
    else if c = "#" then
      v := 38
    end if
    if i is not even then
      v := v × 2
    end if

    sum := sum + int(v div 10) + v mod 10
  repeat

  return (10 - (sum mod 10)) mod 10

Here is a PHP version of the above pseudo code published on stackoverflow.com.

/**
* function to return the check digit value of a cusip
* @param $cusip
*       the cusip for processing.
* @return Int
*       cusip check digit.
*/
function cusip_checksum($cusip){
    $sum = 0;
    $rebuiltcusip = '';
    for($i = 1; $i <= 8; $i++){
        $c = substr($cusip, ($i - 1), 1); //$i needs to be 0, so as we start at 1, take 1 off.
        $rebuiltcusip .= $c;
        switch(true){
            case $c == '0': // ctype_digit(0) returns false, so checking for 0 here.
                $v = $c;
                watchdog("case 0: ", $v);
            break;
            case ctype_digit($c): //check if numeric
                $v = $c;
                watchdog("case ctype_digit: ", $v);
            break;
            case $c == '*':
                $v = 36;
                watchdog("case *: ", $v);
            break;
            case $c == '@':
                $v = 37;
                watchdog("case @: ", $v);
            break;
            case $c == '#':
                $v = 38;
                watchdog("case #: ", $v);
            break;
            case !ctype_digit($c): //check letter last as this check would pass with * @ or # so allow them to be checked first
                $v = (ord($c) - 64) + 9; //set ordinal number, -64 as this returns ASKII value, then add 9.
                watchdog("case not ctype_digit: ", $v);
            break;
        }
        if(($i % 2) == 0){ //check if odd
            $v = $v * 2;
            watchdog("case odd: ", $v);
        }

        $sum = $sum + floor($v / 10) + ($v % 10);
        watchdog("sum end loop: ", $sum);
    }

    $ncd = (10 - ($sum % 10)) % 10;
    $rebuiltcusip .= $ncd;
    watchdog("rebuilt cusip: ", "Cusip: ".$cusip." Rebuilt: ".$rebuiltcusip);
    return $ncd;
}

 

CUSIP vs. ISIN

What Is CUSIP

Introduction on CUSIP

⇑⇑ CUSIP - North American Financial Security ID

2025-06-30, ∼369🔥, 0💬