public async Task CompareNotSimilarTest() { var dataVeryChanged = "The worst docs are the Windows source. After all, this is not what the " + "system uses for docs when it decides what to do next! The " + "manuals paraphrase the source code, often having been written at " + "many times and by the same people than who wrote the code. " + "Think of them as nothing like guidelines. Always are more like wishes... " + "Therefore, it is all too common to ignore sources and find " + "options and weird behaviors that are not put in the docs. Sometimes " + "you find options not described in the docs that are incomplete " + "and weird by the source."; var tlsh = new TlshBuilder(BucketSize.Buckets256, ChecksumSize.Checksum3Bytes); await tlsh.LoadFromStringAsync(data); var hash1 = tlsh.GetHash(false); tlsh.Reset(); await tlsh.LoadFromStringAsync(dataVeryChanged); var hash2 = tlsh.GetHash(false); var match = hash1.TotalDiff(hash2, true); Assert.IsTrue(match > 200); }
public async Task CompareAccuracyTest() { var highAccuracyTlsh = new TlshBuilder(BucketSize.Buckets256, ChecksumSize.Checksum3Bytes); var lowAccuracyTlsh = new TlshBuilder(BucketSize.Buckets128, ChecksumSize.Checksum1Byte); await highAccuracyTlsh.LoadFromStringAsync(data); var highAccuracyHash1 = highAccuracyTlsh.GetHash(false); await lowAccuracyTlsh.LoadFromStringAsync(data); var lowAccuracyHash1 = lowAccuracyTlsh.GetHash(false); highAccuracyTlsh.Reset(); lowAccuracyTlsh.Reset(); await highAccuracyTlsh.LoadFromStringAsync(dataSlightlyChanged); var highAccuracyHash2 = highAccuracyTlsh.GetHash(false); await lowAccuracyTlsh.LoadFromStringAsync(dataSlightlyChanged); var lowAccuracyHash2 = lowAccuracyTlsh.GetHash(false); var highAccuracyMatch = highAccuracyHash1.TotalDiff(highAccuracyHash2, true); var lowAccuracyMatch = lowAccuracyHash1.TotalDiff(lowAccuracyHash2, true); Assert.IsTrue(highAccuracyMatch < 30); Assert.IsTrue(lowAccuracyMatch < 30); Assert.IsTrue(lowAccuracyMatch < highAccuracyMatch); }
public async Task CompareHashTest() { var tlsh = new TlshBuilder(BucketSize.Buckets256, ChecksumSize.Checksum3Bytes); await tlsh.LoadFromStringAsync(data); var hash1 = tlsh.GetHash(false); tlsh.Reset(); await tlsh.LoadFromStringAsync(dataSlightlyChanged); var hash2 = tlsh.GetHash(false); var match = hash1.TotalDiff(hash2, true); Assert.IsTrue(match < 30); }
public async Task HashEncodingTest() { var tlsh = new TlshBuilder(BucketSize.Buckets128, ChecksumSize.Checksum1Byte); await tlsh.LoadFromStringAsync(data); var hash = tlsh.GetHash(false); Assert.AreEqual("6FF02BEF718027B0160B4391212923ED7F1A463D563B1549B86CF62973B197AD2731F8", hash.GetEncoded()); }
public async Task ForceHashEncodingTest() { var shortData = "a quick brown fox jumps over the lazy dog and now this is long enough."; var tlsh = new TlshBuilder(BucketSize.Buckets128, ChecksumSize.Checksum1Byte); await tlsh.LoadFromStringAsync(shortData); var hash = tlsh.GetHash(true); var encodedHash = hash.GetEncoded(); Assert.IsTrue(true); }
public async Task EncodeToStringAndBackTest() { var tlsh = new TlshBuilder(BucketSize.Buckets128, ChecksumSize.Checksum1Byte); await tlsh.LoadFromStringAsync(data); var hash = tlsh.GetHash(false); var encoded = hash.GetEncoded(); var hashFromEncoding = TlshHash.FromTlshStr(encoded); var match = hash.TotalDiff(hashFromEncoding, true); Assert.AreEqual(0, match); }