As I note in a comment above, if you're reading the contents of the file into a string, you need to be careful that you don't strip out line breaks or any other characters—if for example you're calling source.getLines.mkString
you're going to lose the line breaks, which means you won't see the same results as the driver class, which uses Guava's ByteStreams.toByteArray
.
Madcreator Rabinfingerprint command line vs java/scala program
-
30-09-2022 - |
Question
I'm using Madcreator's Rabinfingerprint java library in a scala program, https://github.com/themadcreator/rabinfingerprint.
Using the command line I generate an irreducible 53 degree polynomial:
java -jar rabinfingerprint.jar -polygen 53
31DF3F8C7356D3
Then fingerprint the file:
java -jar rabinfingerprint.jar -p 31DF3F8C7356D3 file.txt
1847CCD86D5DE5 file.txt
The problem I'm having is producing the same output, given the same input, using code.
// Can't create Polynomial from hex above, so convert hex to long and use that:
val polynomial = Polynomial.createFromLong(14037737891124947L)
// val p = java.lang.Long.toString(14037737891124947L, 16)
// p = 31DF3F8C7356D3 same as command line input
val rabin = new RabinFingerprintLong(polynomial)
rabin.pushBytes(text.getBytes)
val fp = rabin.getFingerprintLong
println(java.lang.Long.toString(fp, 16)) // 1acc76a73eed1f
fp.toString // 7543159378603295
// Where is 1847CCD86D5DE5 ?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow