home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky rec.puzzles:8174 can.general:6196
- Newsgroups: rec.puzzles,can.general
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!csservices!volkl!egs
- From: egs@cs.Princeton.EDU (Emin Gun Sirer)
- Subject: Re: GST registration number check digit: puzzle and prize
- Message-ID: <1992Dec31.232852.2665@csservices.Princeton.EDU>
- Originator: egs@volkl
- Sender: news@csservices.Princeton.EDU (USENET News System)
- Reply-To: egs@cs.Princeton.EDU (Emin Gun Sirer)
- Organization: Department of Computer Science, Princeton University
- References: <1992Dec31.044137.22920@sq.sq.com>
- Date: Thu, 31 Dec 1992 23:28:52 GMT
- Lines: 85
-
- dave@lsuc.on.ca (David Sherman) writes:
- >Virtually all businesses in Canada are registered for the Goods and
- >Services Tax (GST) and receive a registration number, which is "R"
- >followed by nine digits.
- >
- >Included in the 9 digits is a check digit. Revenue Canada Excise,
- >which administers the GST, refuses to release the formula for the
- >check digit, stating that it "relates to an internal procedure for
- >verifying registration numbers".
-
- >R123965659 R130134310 R111046959
- [other examples elided to please inews]
-
-
- I believe the last digit is the checksum and and is calculated
- according to Luhn's formula. This is the exact same technique used in
- computing the last digit of credit card numbers.
-
- The last digit is equal to the ten's complement of the sum of twice
- each digit modulo ten. Last time this came up in sci.crypt, someone posted
- the following piece of code to calculate them [code appended at the very end].
-
- Here's a check:
- ;a.out 12396565 12142551 12159807 11019143 13013431 11104695
- 12396565 - 9
- 12142551 - 6
- 12159807 - 2
- 11019143 - 4
- 13013431 - 5
- 11104695 - 9
- ;a.out 10097678 12156037 11104695 10635306
- 10097678 - 6
- 12156037 - 9
- 11104695 - 9
- 10635306 - 3
-
- I'll go one step forward and contend that the 130134310 is a typo
- (or perhaps a typo on the part of the receipt publisher or perhaps is not
- very readable).
-
- There really is nothing magical about this formula, but knowing
- it, one could construct credit card numbers (and perhaps GTEs) that seem
- valid.
-
- Gun.
- #include <stdio.h>
- /*
- * > I am looking for any pointers to information on the algorithms used
- * >to verify credit cards (and similar authentication schemes). For example,
- * >I know that the last digit on most credit cards is typically a checksum.
- * >What is this method actually called? Is is a commercial standard?
- *
- * It is called Luhn's formula. The last digit is the ten's complement of
- * the modulo sum of the other digits where each other digit is doubled.
- * There is an international standard specifying the number codes, and
- * their allocation. The following routine will calculate the checksum
- * number:
- */
- /*
- * Return last digit of a bank card (e.g. credit card)
- * Receives all the digits, but the last one as input
- * By Diomidis Spinellis <dds@doc.ic.ac.uk>
- */
- int bank(char *u) {
- register i, s = 0;
- int l, t;
-
- l = strlen(u);
- for(i = 0; i < l ; i++) {
- t = (u[l - i - 1] - '0') * (1 + ((i + 1) % 2));
- s += t < 10 ? t : t - 9;
- }
- return 10 - s % 10;
- }
-
- void main(int argc, char *argv[]) {
- int i;
- if(argc <= 1) {
- fprintf(stderr,"Usage: %s bankcardno\n", argv[0]);
- exit(1);
- }
- for(i = 1; i < argc; ++i)
- printf("%s - %d\n", argv[i], bank(argv[i]));
- exit(0);
- }
-