Skip to content

Instantly share code, notes, and snippets.

@maxmcd maxmcd/main.go Secret
Created Aug 25, 2019

Embed
What would you like to do?
func validateSFID(input string) bool {
// https://stackoverflow.com/a/29299786/1333724
if len(input) != 18 {
return false
}
parts := []string{input[0:5], input[5:10], input[10:15]}
chars := make([]byte, 3)
for j, word := range parts {
for i, char := range []byte(word) {
// fmt.Println([]byte("AZ")) => [65 90]
if char >= 65 && char <= 90 {
chars[j] += 1 << uint64(i)
}
}
}
for i, c := range chars {
if c <= 25 {
chars[i] = c + 65
} else {
chars[i] = c - 25 + 48
}
}
if string(chars) == input[15:] {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.