~mendelmaleh/checksum

ref: e71e2f6f91dd70e3fd9fce07672614204fce5348 checksum/damm.go -rw-r--r-- 645 bytes
e71e2f6fMendel E Initial commit 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package checksum

var quasi = [10][10]int{
	{0, 3, 1, 7, 5, 9, 8, 6, 4, 2},
	{7, 0, 9, 2, 1, 5, 4, 8, 6, 3},
	{4, 2, 0, 6, 8, 7, 1, 3, 5, 9},
	{1, 7, 5, 0, 9, 8, 3, 4, 2, 6},
	{6, 1, 2, 3, 0, 4, 5, 9, 7, 8},
	{3, 6, 7, 4, 2, 0, 9, 5, 8, 1},
	{5, 8, 6, 9, 7, 2, 0, 1, 3, 4},
	{8, 9, 4, 5, 3, 6, 2, 0, 1, 7},
	{9, 4, 3, 8, 6, 1, 7, 2, 0, 5},
	{2, 5, 8, 1, 4, 3, 6, 7, 9, 0},
}

func damm(i, n, c int) int {
	return quasi[c][n]
}

// Damm checksum validation
func Damm(num int) bool {
	return IterOppositeInt(num, damm) == 0
}

// GetDamm calculates the Damm checksum digit for num.
func GetDamm(num int) int {
	return IterOppositeInt(num, damm)
}