Transcript *** 1
ELEC332 Presentation
HKID & Credit Card Number Verification
Chan Ka Shing, Yuemin Lu, Tang Shuk Fan
1
Luhn Algorithm
Created by IBM scientist Hans Peter Luhn
Simple checksum formula used to validate
identification numbers
Many extensions
Classical Algorithm Logic
Double the value of every second digit counting from the
check digit
Sum all the digits
Mod 10
XXXXXXXXXXXXX Y
X = account number, Y = check digit
2
Luhn Algorithm
Strengths and Weaknesses
3
Detect single-digit error
Almost all transposition of adjacent digits except 09 and
90
Detect some twin errors
Credit Card Verification
Credit Card pattern 8267 1232 7351 0569
Example:
16-bit Credit Card = Codeword
4
Double every other number, starting with the second
number in from the right
If a number has two digits, add both digits together
Credit Card Verification
5
Add all numbers together
If last digit is a zero, it is a valid credit card number. If
not, the credit card number is a fake.
HKID Verification
HK digit pattern X9999999/X999999(C)
Each letter matches to a corresponding number
6
Number
Letter
Number
Letter
1
ALM
7
GR
2
BMX
8
HS
3
CNY
9
IT
4
DOZ
10
JU
5
EP
11
KV
6
FQ
HKID Verification
Example: C546234(5)
8-bit HKID = Codeword
First 7-bit = Message
Last bit = Check Bit
CheckSum
=char[1]*8+char[2]*7+char[3]*6+char[4]*5+char[5]*4+cha
r[6]*3+char[7]*2
=3(C)*8+5*7+4*6+6*5+2*4+3*3+4*2
=138
Check Bit
=11-(CheckSum mod 11) = 11-(138mod11)
=5
C546234(5) is a valid HKID.
7
HKID Verification
Assume a single error is represented by e
Example: C546e34(5)
CheckSum
=char[1]*8+char[2]*7+char[3]*6+char[4]*5+e*4+cha
r[6]*3+char[7]*2
=3(C)*8+5*7+4*6+6*5+e*4+3*3+4*2
=130+4e
Check Bit
=11-(CheckSum mod 11)
=11-(130+4e)mod11=11-(9+4e)mod11
8
HKID Verification
If Check Bit == 5
=>11-(9+4e)mod11 = 5
=>(9+4e)mod11 = 6
=>9+4e = 11n+6 n is an positive integer
=>e = (11n-3)/4
e
0
1
2
3
4
5
6
7
8
9
n
3/11
7/11
1
15/11
19/11
23/11
27/11
31/11
35/11
39/11
Single bit error is detected.
9