0
私はGroovyでCRC32を計算するプログラムを書いています。CRC32の計算がデフォルトのものと一致しません
def crc32(byte[] bytes) {
return new java.util.zip.CRC32().with { update bytes; value }
}
def myCrc32(byte[] bytes) {
def remainder = 0x0
def multiple = 0
def poly = 0xEDB88320
bytes.each { b ->
remainder ^= b
for (int i = 0; i < 8; i++) {
multiple = (remainder & 1) ? poly : 0;
remainder = (remainder >> 1)^multiple;
}
}
return remainder
}
def origFile = 'file'
def fileBytes = new File(origFile).text.getBytes()
def origRes = crc32(fileBytes)
def myRes = myCrc32(fileBytes)
println origRes
println myRes
が、私は間違いをしました:何らかの理由で私は(私はjava.util.zip
実装を使用する場合と同じ)の期待値を得ることはありませんか?私はガイドとして、以下のソースを使用:私が得る
結果:
1838399800 - original
4005013284 - my calculation