Credit cards. Nearly everybody has at least one. Its not wrong to say that credit cards are life lines of worlds financial system.
But how many of you know what those numbers really mean? Contrary to what you may think, they aren’t random. Those 16 digits (15 for American Express) are there for a reason and, knowing a few simple rules, we can actually learn a lot about a credit card just from its number. The first two digits indicate what brand of credit or debit card it is, the first four or first six indicate what organization issued it and what type of card it is (credit, debit, prepaid, gift). The last digit is a checksum which determines if the number is valid. This checksum, called the “Luhn Code” determines if the number is in correct form and helps to prevent transposition errors.
Head to this infographics to crack that code. And check the below mentioned Fortran program to Validate any credit and debit card number.
PROGRAM CREDITCARD
! Program to Validate a credit or debit card number
! coded by Sukhbinder Singh
! based on http://www.mint.com/blog/trends/credit-card-code-01202011/
CHARACTER (LEN=16) CCN
INTEGER ICCN(16),ODD(8),EVN(8)
WRITE(*,'(A)',ADVANCE='NO')"ENTER YOUR CREDIT CARD NO : "
READ(*,'(A16)') CCN
DO I=1,16
READ(CCN(I:I),'(I1)') ICCN(I)
END DO
ODD=ICCN(1:16:2)
ODD=ODD*2
CALL SUMODD
EVN =ICCN(2:16:2)
IF(MOD(SUM(EVN)+SUM(ODD),10) .EQ. 0) THEN
WRITE(*,*) "THE CREDIT OR DEBIT CARD NO IS VALID!"
ELSE
WRITE(*,*) "THE CREDIT OR DEBIT CARD NO IS INVALID!"
END IF
CONTAINS
SUBROUTINE SUMODD
DO I=1,8
IF(ODD(I) .GE. 10) THEN
K=ODD(I)-10
ODD(I)=1+K
END IF
ENDDO
END SUBROUTINE
END PROGRAM