/usr/lib/interchange/code/OrderCheck/isbn.oc is in interchange 5.7.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # Copyright 2008,2009 Interchange Development Group
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
CodeDef isbn OrderCheck 1
CodeDef isbn Description ISBN-10/ISBN-13 check digit verification
CodeDef isbn Routine <<EOR
sub {
my($ref, $var, $val, $msg) = @_;
my($len);
if ($msg =~ s/^\s*(10|13)\s*//) {
$len = $1;
}
$val =~ s/[^\dXx]//g; # weed out non-digits
if ($val) {
my @digits = split("", $val);
my $sum = 0;
my $check_digit = 0;
my $modulo;
if (@digits == 10 ) {
# ISBN-10 number
if ($len == 13) {
return (0, $var, errmsg("'%s' not a valid isbn-13 number", $val));
}
for(my $i=10; $i > 0; $i--) {
my $d = $digits[10 - $i];
if ($d =~ /[Xx]/) {
if ($i == 1) {
$d = 10;
}
else {
return (undef, $var, errmsg("'%s' not a valid isbn number", $val));
}
}
$sum += $d * $i;
}
return ( $sum%11 ? 0 : 1, $var, '' );
} elsif (@digits == 13) {
# ISBN-13/EAN number
if ($len == 10) {
return (0, $var, errmsg("'%s' not a valid isbn-10 number", $val));
}
for (my $i = 0; $i < 12; $i++) {
if ($i % 2) {
$sum += 3 * $digits[$i];
}
else {
$sum += $digits[$i];
}
}
if ($modulo = $sum % 10) {
$check_digit = 10 - $modulo;
}
if (pop(@digits) == $check_digit) {
# verification successful
return (1, $var, '');
}
}
}
return (undef, $var, errmsg("'%s' not a valid isbn number", $val));
}
EOR
|