Luhn validates the provided data using the Luhn algorithm.
(s []byte)
| 11 | |
| 12 | // Luhn validates the provided data using the Luhn algorithm. |
| 13 | func Luhn(s []byte) bool { |
| 14 | n := len(s) |
| 15 | number := 0 |
| 16 | result := 0 |
| 17 | for i := 0; i < n; i++ { |
| 18 | number = int(s[i]) - '0' |
| 19 | if i%2 != 0 { |
| 20 | result += number |
| 21 | continue |
| 22 | } |
| 23 | number *= 2 |
| 24 | if number > 9 { |
| 25 | number -= 9 |
| 26 | } |
| 27 | result += number |
| 28 | } |
| 29 | return result%10 == 0 |
| 30 | } |
no outgoing calls