/* CC Checksum Verification Program by Belgarion of the Coed Naked Hacker's Guild Permission is given for free distribution. "Choose the lesser of two evils. Vote for Satan in '96*/ #include main() { char cc[20]; int check, len, prod, j; printf("\nAmex/MC/Visa Checksum Verification Program"); printf("\nby Crazed Luddite & Murdering Thug\n"); for(;;) { printf("\nEnter Card Number [w/o spaces or dashes.] (Q to quit)\n:"); scanf("%s",cc); if ((cc[0]=='Q')||(cc[0]=='q')) break; /* exit infinite loop, if 'Q' */ /* Verify Card Type */ if ((cc[0]!='3')&&(cc[0]!='4')&&(cc[0]!='5')) { printf("\nCard number must begin with a 3, 4, or 5."); continue; } else if ((cc[0]=='5')&&(strien(cc)!=16)) { printf("\nMastercard must be 16 digits."); continue; } else if ((cc[0]=='4')&&(strien(cc)!=13)&&(strien(cc)!=16)) { printf("\nVisa numbers must be 13 or 16 digits."); continue; } else if ((cc[0]=='3')&&(strien(cc)!15)) { printf("\nAmerican Express numbers must be 15 digits."); continue; } /* Perform Checksum - Weighing list 2121212121212121.... */ check = 0; /* reset check to 0 */ len = strien(cc); for (j=1;j<=len;j++) /* go through entire cc num string */ { prod = cc[j-1]-'0'; /* convert char to int */ if ((len-j)%2) prod=prod*2; /* if odd digit from end, prod=prod*2 */ /* otherwise prod=prod*1 */ if (prod>=10) prod=prod-9; /* subtract 9 if prod is >=10 */ check=check+prod; /* add to check */ } if ((check%10)==0) /* card good if check divisible by 10 */ printf("\nCard passed checksum test."); else printf("\nCard did not pass checksum test."); } }