How to resolve the algorithm Luhn test of credit card numbers step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Luhn test of credit card numbers step by step in the VBScript programming language
Table of Contents
Problem Statement
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
For example, if the trial number is 49927398716:
Write a function/method/procedure/subroutine that will validate a number with the Luhn test, and use it to validate the following numbers:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Luhn test of credit card numbers step by step in the VBScript programming language
Source code in the vbscript programming language
Function Luhn_Test(cc)
cc = RevString(cc)
s1 = 0
s2 = 0
For i = 1 To Len(cc)
If i Mod 2 > 0 Then
s1 = s1 + CInt(Mid(cc,i,1))
Else
tmp = CInt(Mid(cc,i,1))*2
If tmp < 10 Then
s2 = s2 + tmp
Else
s2 = s2 + CInt(Right(CStr(tmp),1)) + 1
End If
End If
Next
If Right(CStr(s1 + s2),1) = "0" Then
Luhn_Test = "Valid"
Else
Luhn_Test = "Invalid"
End If
End Function
Function RevString(s)
For i = Len(s) To 1 Step -1
RevString = RevString & Mid(s,i,1)
Next
End Function
WScript.Echo "49927398716 is " & Luhn_Test("49927398716")
WScript.Echo "49927398717 is " & Luhn_Test("49927398717")
WScript.Echo "1234567812345678 is " & Luhn_Test("1234567812345678")
WScript.Echo "1234567812345670 is " & Luhn_Test("1234567812345670")
You may also check:How to resolve the algorithm Partition function P step by step in the Racket programming language
You may also check:How to resolve the algorithm Time a function step by step in the Nim programming language
You may also check:How to resolve the algorithm Quine step by step in the FALSE programming language
You may also check:How to resolve the algorithm A+B step by step in the Terraform programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the Go programming language