home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3971 < prev    next >
Text File  |  1991-09-04  |  3KB  |  88 lines

  1. Xref: wupost comp.misc:8338 misc.misc:8172 rec.misc:883 alt.sources:3971
  2. Path: wupost!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!gvlf3.gvl.unisys.com!widener!news
  3. From: sven@cs.widener.edu (Sven Heinicke)
  4. Newsgroups: comp.misc,misc.misc,rec.misc,alt.sources
  5. Subject: Re: ISBN check sum digit
  6. Message-ID: <kca87gINN8iv@ashley.cs.widener.edu>
  7. Date: 4 Sep 91 18:07:44 GMT
  8. References: <1991Sep3.182314.4794@edsr.eds.com>
  9. Followup-To: comp.misc
  10. Organization: Widener CS Dept
  11. Lines: 65
  12. NNTP-Posting-Host: ashley.cs.widener.edu
  13.  
  14. n
  15. In <1991Sep3.182314.4794@edsr.eds.com>, jamii@edsr.eds.com writes:
  16. >   0-xxx-yyyy-z  where xxx seems to be publisher code, yyyy is the book code,
  17. > the 0 is the language (or country) code. Does anyone know if this speculation
  18. > is correct, and if so what the check digit algorithm is? It doesn't seem to
  19. > be a simple summation, since I have 3 books that differ only in the last y
  20. > digit, and only by one, and the check digit differs by 2 in each case.
  21. Xref: widener comp.misc:2342 misc.misc:1846 rec.misc:199 alt.sources:1166
  22.  
  23. Here is a program I hacked together a few months ago that will tell
  24. you if an ISBN code is good or not.  It is just a 10D dot product with
  25. the numbers that are coprime to 11 (1 to 10).  Because 10 is coprime
  26. to 11 too, and 10 is not a single digit the ISBN code uses a X instead
  27. of 10, X is only used when it is the check digit (so far what I have
  28. found).  I only know about the check digit, I don't know about the xxx
  29. and yyyy digits.
  30.  
  31. There is a proof (I got it from "Abstract Algebra" by J. Gallen (I
  32. don't know the ISBN number)) but I will not resite it right here,
  33. right now.
  34.  
  35. About my program, I worte in using GNU C on a Sun sparc 1, have not
  36. tried it anywhere else and I have not trouble shooted very much.
  37.  
  38. /* International Standard Book Number (ISBN) tester. 
  39.    By Sven Heinicke */
  40. #include <stdio.h>
  41.  
  42. int isbn();
  43.  
  44. main(argc,argv)
  45.      int argc;
  46.      char **argv;
  47. {
  48.   char *code,reply;
  49.  
  50.   if(argc == 1)
  51.     {
  52.       code = (char*)malloc(sizeof(char) * 14);
  53.       printf("Enter a ISBN code: ");
  54.       fflush(stdout);
  55.       scanf("%s",code);
  56.     }
  57.   else
  58.     code = *(argv + 1);
  59.   printf("The ISBN code %s is ",code);
  60.   reply = isbn(code);
  61.   if(reply == 0)
  62.     puts("good.");
  63.   else
  64.     printf("bad.\nThe checksum returned %d.\n",reply);
  65. }
  66.  
  67. int isbn(code)
  68.      char *code;
  69. {
  70.   int loop,n = 0;
  71.  
  72.   for(loop = 10;loop > 0;loop--)
  73.     {
  74.       if(*code == '-')
  75.     code++;
  76.       if((loop == 1) && ((*code == 'x') || (*code == 'X')))
  77.     n += 10;
  78.       else
  79.     n += (*code - '0') * loop;
  80.       code++;
  81.     }
  82.   return(n % 11);
  83. }
  84. -- 
  85. sven@cs.widener.edu                                  Widener CS system manager
  86. Sven Mike Heinicke                                          and Student
  87. (pssmheinicke@cyber.widener.edu (if you must))
  88.