Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }