• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Modulus 10

 
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Glen. I'll check it out.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But is there a way to check the expire date too ?
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic