Here is a simple example in freebasic that implements the Luhn's algorithm. It is a literal translation of a Pascal source code found in Internet.

function luhn(arg as String) as String
  Dim xpos as Integer
  Dim sum as Integer
  Dim temp as Byte
    sum = 0
    for xpos = len(arg)-1 to 0 step -1		'Run the characters backwards
      temp = arg[xpos]-48			'Convert from ASCII to byte
      if (len(arg)-xpos-1) mod 2 = 0 then
        sum = sum + temp			'Odd characters just add
       if temp < 5 then
         sum = sum + 2*temp			'Even characters add double
        sum = sum + (2*temp)-9			'or sum the digits of the doubling
      end if
     end if
    next xpos
    function = "False"
    if (sum mod 10) = 0 then function = "True"	'Return "True" if sum ends in a 0
end function
Dim CrCd as String
Dim Numb as String
Dim N as Integer
Print "Credit card number xxxx-xxxx-xxxx-xxxx"
Input CrCd
Numb = ""
For N = 0 to len(CrCd)-1
 if chr (CrCd[N]) <> "-" then
  Numb = Numb + chr (CrCd[N])
 end if
Next N
Print "Card number "; Numb; " is "; luhn(Numb)
Vzpostavljeno iz »«