Skip to content

Instantly share code, notes, and snippets.

@stackdump
Created March 10, 2025 15:45
Show Gist options
  • Save stackdump/93e4c42ce88a4f718918376410612e70 to your computer and use it in GitHub Desktop.
Save stackdump/93e4c42ce88a4f718918376410612e70 to your computer and use it in GitHub Desktop.
Use trailing digits as a checksum
package main
import (
"fmt"
)
func checksum3Digit(s string) int {
sum := 0
for _, c := range s {
sum += int(c) // Convert character to ASCII and sum it
}
return sum % 1000 // Ensure it's a 3-digit number
}
func ExampleChecksum3Digits() {
input := "stackdump"
checksum := checksum3Digit(input)
fmt.Printf("%s%03d\n", input, checksum) // Prints checksum with leading zeros if needed
// Output:
// stackdump972
}
@stackdump
Copy link
Author

For use w/ pre-release user realms allowing users's to register w/ 3 digit trailing number.

Individual users could adopt this scheme to claim idempotent names despite not getting a vanity name

gnolang/gno#2827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment