• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modulus 10

 
Ray Marsh
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure where this question should go.
Has anyone heard of a mod10 check in Java? Perhaps a class already exists that handles the logic.
Modulus 10 for those who are unfamiliar is a format check for credit card numbers. It does not authorize dollar amounts or even check if the account is active. All it does is perform a complicated algorithm on the credit card number to see if it is valid. Example '1111 1111 1111 1111' would fail. There are certain patterns that must exist in a CC number for it to pass mod10.
Thanks in advance.
 
Glen Tanner
Ranch Hand
Posts: 147
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a post on the Sun site with a code example, but I'm not sure if that is what you're looking for.
http://forum.java.sun.com/forum?14@@.eef01e5
 
Ray Marsh
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Glen. I'll check it out.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just tried the code from that site. It's a bit of a mess, but it does work.
 
Glen Tanner
Ranch Hand
Posts: 147
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should have at least tried the code!
 
Ray Marsh
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
I've just tried the code from that site. It's a bit of a mess, but it does work.

Thanks Frank.
How did you test the code? I'm having some trouble with it.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I reformatted it, wrapped it up in a class and tried it with the numbers on my credit cards, and a few other known wrong ones.

For obvious reasons I'm reluctant to give you my test data!
 
Ray Marsh
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank.
I don't need ALL your test data. Just your CC number, expiration date and credit limit. But I promise not to tell anyone!
 
Manju Swamy
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an improvised version. This does not have a card number digits limitation. Also when use isDigit() function it reruns true for various other language (like Indian, Arabic, etc.) numbers. Then the whole logic would fail.

[This message has been edited by Manju Swamy (edited March 03, 2000).]
[This message has been edited by Manju Swamy (edited March 03, 2000).]
 
Ray Marsh
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Manju.
I'll give that one a test drive as well.
I have a modulus 10 routine in RPG that has been in production for a few years. The specs for the logic is on IBM's AS400 book shelf web-site in their DDS reference manual.
Once I have one or two working Java programs, I plan to run some parallel testing. It will be interesting to see what happens.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing all that math? Putting the results of the calculations in a static array would make it much faster/easier to read. Pseudocode follows.
public class CCThingy
{
public static int[] results = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
public boolean checkIt(int ccarray[])
{
// Sanity checking removed, you can figure
// that out for yourselves.
boolean flip = false;
int sum = 0;
for(int i = ccarray.length; i >= 0; i--)
{
if(flip)
{
sum += results[ccarray[i]];
} else {
sum += ccarray.length[i];
}
}
return (sum % 10 == 0);
}

This way you don't have to calculate values that aren't going to ever change. And you don't have to multiply something by 1.


------------------
--I'm Hugh Jass.
 
Mark Barell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is there a way to check the expire date too ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic