Last active
January 30, 2021 05:38
-
-
Save Sansui233/0a56ceaed0d78e89f7a50404b3cebcf4 to your computer and use it in GitHub Desktop.
crc32 encoding and decoding example / bilibili uid hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| // IEEE is crc32b, which is used to hash bilibili uid | |
| // Encode | |
| uid := "21670130" | |
| h := fmt.Sprintf("%x", crc32.ChecksumIEEE([]byte(uid))) | |
| fmt.Printf("Encoding of %s: %s\n", uid, h) | |
| // Decode | |
| hashed := "6acc8733" | |
| fmt.Printf("Start Decoding... \n") | |
| for i := 1; i < 500000000; i++ { | |
| h = fmt.Sprintf("%x", crc32.ChecksumIEEE([]byte(strconv.Itoa(i)))) | |
| if fmt.Sprintf("%s", h) == hashed { | |
| fmt.Printf("\rProgress: Completed\n") | |
| fmt.Printf("Decoding of %s: %d \n", hashed, i) | |
| } | |
| if i%50000 == 0 { | |
| fmt.Printf("\rProgress: %5.2f%%", float64(i)*100 / float64(500000000)) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment