A really tough one.....impossible??

marklane

New Member
Joined
Apr 19, 2007
Messages
10
Hi

I am curently testing a web application and part of that requires me to create some test credit card data to perform checks on each type of card there is. What I have is a spreadsheet with the following:

CARD_NAME - CARD_TYPE - CARD_LENGTH - PREFIX
solo debit 16 633450
visa credit 16 4535
Mastercard credit 14 52

The first check the system does is to check that the card entered begins with the correct PREFIX e.g. 633450. The secon is checks is that the CARD_LENGTH is correct length. So first of all I need a formula that generates a card number in another celll say E1 dependant on these these things e.g.
E1 for the first line would generate a number that is 16 numbers in length and starts 633450 (the 16 numbers include the 633450 so would need another 10).

To make this even harder there is another check the sytem does called a LUHN check which does the following:
To check the LUHN digit of a card number for example 6333 0410 0135 4512 , each digit is multiplied by the alternating factors 2 and 1 (last digit is always multiplied by 1). Of each calculation result, the digits of the results are summed together. Then these sums are totalised.
e.g.
6 3 3 3 0 4 1 0 0 1 3 5 4 5 1 2
x x x x x x x x x x x x x x x x
2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1
1+2 +3+6+3 4+2+ 1+6+5+ 8+5+2+2 =50

The result is divisible by 10 withut a remainder so the card passes the check.

So to recap:

The card must start with the relevant prefix included in the number. The lenght is generated dependant on the card length field and it MUST pass the LUHN check!!
Don't want much do I ;-) :-D

I know this is probably not possible but I know how good you guys are so what do you think???? P[/b]
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Doesnt seem that difficult.

Do different card types have different prefix numbers ?

How do you get 6*2=1 ?
 
Upvote 0
...

Yes different card types have different prefixes and those prefixes are different lengths and so are the card numbers.

6 * 2 = 12 but in the LUHN check it will be 1+2. Each single number added
 
Upvote 0
First thing I would do, would be to tabulate the card type and prefix numbers. Then you can use vlookup() to check the validity of the number/card combination.
 
Upvote 0
Hi,
would these be correct numbers for mastercard?

52594879886892
52592464386666
52932218935071
52723586204202

Regards
 
Upvote 0
looking good

The first ones look fine thanks. I only need 1 card number for each card type (there are over 500 of them). I am using an automated test tool that will enter the number from the excel sheet and so need to generate one number for each card type
 
Upvote 0
A formula would be best but a VBA solution is fine as long as it can be called into the relevant cell to generate the number

Thanks
 
Upvote 0
Hi Mark

I believe the following will auto-generate card numbers (as long as the length of the number is an even number) and will perform the LUHN check:
Book1
ABCDEFGH
1CARD_NAMECARD_TYPECARD_LENGTHPREFIXCalculated Card NumberLen Cal CnumLUHN NoLUHN Check
2solodebit1663345063345052581505271652FALSE
3visacredit16453545354976758462441690TRUE
4Mastercardcredit1452522527508104021438FALSE
Sheet1


Formula in E2 copied down:

Code:
=D2&LEFT(TEXT(RAND()*1000000000000,"000000000000"),C2-LEN(D2))

Formula in F2 (just a check):

Code:
=LEN(E2)

Formula in G2 (this is an array formula so needs to be confirmed with Ctrl+Shift+Enter):

Code:
=SUM(--MID(TEXT(MID(E2,ROW(INDIRECT("1:"&F2)),1)*(MOD(ROW(INDIRECT("1:"&C2)),2)+1),"00"),{1,2},1))

Formula in H2:

Code:
=MOD(G2,10)=0

You can repeatedly hit F9 to recalculate alternative Credit card numbers that will be checked.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top