home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hcshdemo.zip / csh-os2.zip / SAMPLES / MCVISA.CSH < prev    next >
Text File  |  1993-09-28  |  797b  |  28 lines

  1. #    This is a self-loading procedure that can tell whether a MasterCard
  2. #    or Visa credit card number is plausible by constructing a special
  3. #    checksum of the digits.   The checksum used for credit cards is
  4. #    designed to catch transposed or incorrect digits.  For fun, try it
  5. #    on the cards in your wallet!
  6.  
  7. #    Copyright (c) 1990 by Hamilton Laboratories.  All rights reserved.
  8.  
  9. proc mcvisa(card)
  10.     local i, j, sum
  11.     @ sum = 0
  12.     # reverse the digits and discard any spaces.
  13.     @ card = reverse(card)
  14.     if (card =~ "* *") @ card = $card:gs/ //
  15.     if (card =~ "*[^0-9]*") return "bad"
  16.     for i = 1 to strlen(card) do
  17.         @ j = substr(card, i, 1)
  18.         if (i % 2 == 0) then
  19.             @ j *= 2
  20.             if (j >= 10) @ j -= 9;
  21.         end
  22.         @ sum += j
  23.     end
  24.     return sum % 10 == 0 ? "good" : "bad"
  25. end
  26.  
  27. mcvisa $argv
  28.