Domino Code Fragment

Code Name*
Credit card validation function (ROT13)
Date*
11/25/98
Source (or email address if you prefer)*
Jamie Magee
IP address:.18.222.240.21
Description*
Returns true if a string is a valid credit card number.
Type*
LotusScript
Categories*
Numeric Processing, Security
Implementation:
Modify constants
Required Client:
4.0
Server:
4.0
Limitations:
The main purpose of this algorithm is to avoid data entry errors, not as a security tool, since anybody can crack it.
Comments:
"For a card with an even number of digits, double every odd numbered digit and substract 9 if the product is greater than 9. Add up all the even digits as well as the doubled odd digits, and the result must be a multiple of 10 or it's not a valid card. If a card has an odd number of digits, perform the same addition, doubling the even numbered digits instead..."
Files/Graphics attachments (if applicable): Code:

       Function ValidateCC( strCC As String ) As Integer
      'Credit card validation algorithm
      'By Mark Dixon, Ives Development
      'Derived from http://prope.insa-lyon.fr/~fcoppola/credit.html
      'Parameter: strCC
      ' A string containing the card number to be validated.
      ' May contain non-numeric characters, e.g. spaces or dashes
      'Return value:
      ' True if the card number is good, False if the number is bad


       Dim nCheckSum As Integer
      Dim fDbl As Integer
      Dim nCharPos As Integer
      Dim nChar As Integer


       fDbl = False
      nCheckSum = 0


       'Read the card number from right to left
      For nCharPos = Len( strCC ) To 1 Step -1
      nChar = Asc( Mid( strCC, nCharPos, 1 ) ) - Asc( "0" )
      'Only process if the current character is a digit
      If 0 <= nChar And nChar <= 9 Then
      If ( fDbl ) Then
      nChar = nChar * 2
      If 10 <= nChar Then
      nChar = nChar - 9
      End If
      End If
      nCheckSum = nCheckSum + nChar
      fdbl = Not fdbl
      End If
      Next


       If nCheckSum Mod 10 = 0 Then ValidateCC = True Else ValidateCC =
      False
      End Function