我正在用 Go 编写一个实用程序,可用于计算输入字符串的 CRC32 校验和。Java 中存在类似的实用程序,我们正在广泛使用它,并且一直运行良好。
Java 实用程序用于java.util.zip.CRC32
计算校验和。伪代码如下:
public static void main(String[] args) {
final Checksum checksum = new CRC32();
byte[] input1Bytes = "input1".getBytes(StandardCharsets.UTF_8);
checksum.update(input1Bytes, 0, input1Bytes.length);
final byte[] input2Bytes = "input2".getBytes(StandardCharsets.UTF_8);
checksum.update(input2Bytes, 0, input2Bytes.length);
final byte[] input3Bytes = "input3".getBytes(StandardCharsets.UTF_8);
checksum.update(input3Bytes, 0, input3Bytes.length);
System.out.println("Checksum in Java : " + checksum.getValue());
}
Run Code Online (Sandbox Code Playgroud)
Go中的实用程序使用Go SDK(版本1.13.6)包crc32
中的( )Go中生成校验和的伪代码如下:hash
import "hash/crc32"
table := crc32.MakeTable(0)
checksum := crc32.Checksum([]byte("input1"), table)
checksum = crc32.Update(checksum, table, []byte("input2"))
checksum = crc32.Update(checksum, table, []byte("input3"))
log.Printf("Checksum in …
Run Code Online (Sandbox Code Playgroud)