We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 495cff8 commit 888fca0Copy full SHA for 888fca0
checksum/fletcher32.go
@@ -0,0 +1,22 @@
1
+// Package checksum provides functions for calculating various checksum values.
2
+package checksum
3
+
4
+import (
5
+ "fmt"
6
+)
7
8
+// Fletcher32 computes the Fletcher-32 checksum of the input data.
9
+func Fletcher32(data []byte) uint32 {
10
+ var sum1, sum2 uint32 = 0xff, 0xff
11
+ for _, byte := range data {
12
+ sum1 = (sum1 + uint32(byte)) % 0xff
13
+ sum2 = (sum2 + sum1) % 0xff
14
+ }
15
+ return (sum2 << 8) | sum1
16
+}
17
18
+// Fletcher32Hex computes the Fletcher-32 checksum of a string and returns it as a hexadecimal string.
19
+func Fletcher32Hex(input string) string {
20
+ fletcher := Fletcher32([]byte(input))
21
+ return fmt.Sprintf("%08X", fletcher)
22
0 commit comments