/*Verifiers.c * By: Adrien Kwok * This code is licensed under the General Public License Version 2. * Year: 2008 * Easter Egg: dropped on Windows version as it heavily depends on UNIX. */ #include #include #include void initSIN(){ char SIN[10]; int intArray[9]; int intArray2[4]; int intCount; while(1) { printf("\nFor security reasons, your SIN will be wiped from memory after each verification.\n\n"); while(1) { printf("Please enter your SIN (Type 0 to menu): "); scanf ("%s", SIN); int error = 0; // no error for (intCount = 0; intCount<9; intCount++) { if(SIN[intCount] < '0' || SIN[intCount] > '9') { error = 1; // error } intArray[intCount] = (int)(SIN[intCount] - '0'); } if (error == 1 || intArray[0]){ system ("cls"); intCount = 0; break; } } if (intArray[0] == 0 || SIN[0] == '0') break; // exit the program if user enters '0' intCount = 0; // step 1 intArray2[0] = intArray[1] * 2; intArray2[1] = intArray[3] * 2; intArray2[2] = intArray[5] * 2; intArray2[3] = intArray[7] * 2; // step 2 int intSum = 0; if (intArray2[0] < 10) intSum += intArray2[0]; else intSum += intArray2[0] - 9; if (intArray2[1] < 10) intSum += intArray2[1]; else intSum += intArray2[1] - 9; if (intArray2[2] < 10) intSum += intArray2[2]; else intSum += intArray2[2] - 9; if (intArray2[3] < 10) intSum += intArray2[3]; else intSum += intArray2[3] - 9; // step 3 int intOrig = intArray[0] + intArray [2] + intArray[4] + intArray[6]; // step 4 int intFinal = intSum + intOrig; // step 5 int intRound = ((intFinal - 1) / 10 + 1) * 10; // round up to the nearest 10 int intDiff = intRound - intFinal; if (intDiff == intArray[8]) { for (intCount = 0; intCount<9; intCount++){ intArray[intCount] == 0; } printf("Your SIN number is valid.\n"); } else { for (intCount = 0; intCount<9; intCount++){ intArray[intCount] == 0; } printf("Your SIN number is invalid.\n"); } } } void initISBN(){ while(1){ printf("Please enter your 10-digit ISBN Number (Type 0 to menu): "); long long ISBN; scanf("%lld", &ISBN); if (ISBN <= 0) { system ("cls"); break; } long long ISBNSum=(ISBN/1000000000LL)*10 + ((ISBN/100000000LL)%10)*9 + ((ISBN/10000000LL)%10)*8 + ((ISBN/1000000LL)%10)*7 + ((ISBN/100000LL)%10)*6 + ((ISBN/10000)%10)*5 + ((ISBN/1000)%10)*4 + ((ISBN/100)%10)*3 + ((ISBN/10)%10)*2 + (ISBN%10*1); if (ISBNSum % 11 == 0 && ISBN != 0) { printf("Congratulations, your ISBN is valid!\n"); } else { printf("Sorry, your ISBN is invalid!\n"); } } } void initUPC(){ while(1) { printf("Please enter your 12 digit UPC Code (Type 0 to menu): "); long long UPC; scanf("%lld", &UPC); if(UPC == 0) { system ("cls"); break; } long long UPCSum = (UPC/100000000000LL) + ((UPC/1000000000LL)%10) + ((UPC/10000000LL)%10) + ((UPC/100000LL)%10) + ((UPC/1000)%10) + ((UPC/10)%10); UPCSum = UPCSum * 3; long long UPCSum2 = ((UPC/10000000000LL)%10) + ((UPC/100000000LL)%10) + ((UPC/1000000LL)%10) + ((UPC/10000)%10) + ((UPC/100)%10); long long UPCTotal = UPCSum + UPCSum2; if ((UPCTotal + (UPC % 10)) % 10 == 0) { printf("Your UPC Code is Valid!\n"); long long UPCCom = UPC / 1000000; long long UPCProd = UPC % 1000000; UPCProd /= 10; if((UPCCom/100000 == 0)){ printf("Your company code: 0%lld\n", UPCCom); }else{ printf("Your company code: %lld\n", UPCCom); } printf("Your product code: "); if((UPCProd%100000 < 10000)){ printf("0"); } if((UPCProd%100000 < 1000)){ printf("0"); } if((UPCProd%100000 < 100)){ printf("0"); } if((UPCProd%100000 < 10)){ printf("0"); } if((UPCProd%100000 < 1)){ printf("0"); } printf("%lld\n", UPCProd); }else{ printf("Your UPC Code is Invalid!\n"); } } } void initClr(){ system("cls"); } main(){ system ("cls"); printf("Welcome to the Verification Centre!\n\n"); while(1){ printf("Main Menu\n"); printf("[1] Social Insurance Number Verifier\n"); printf("[2] ISBN Verifier\n"); printf("[3] UPC Verifier\n"); printf("[4] Reset Screen\n"); printf("[0] Exit\n"); printf("Please make a selection: "); int intSelection; scanf("%d", &intSelection); int flagExit = 0; switch (intSelection) { case 1: initSIN(); break; case 2: initISBN(); break; case 3: initUPC(); break; case 4: initClr(); break; case 0: { flagExit = 1; system ("cls"); break; } default: { system ("cls"); printf("Invalid input!\n\n"); } } if (flagExit) break; } }