trendmicro / tlsh

Other
732 stars 136 forks source link

How to compute the distance for two hash strings C++ #68

Closed VISWESWARAN1998 closed 5 years ago

VISWESWARAN1998 commented 5 years ago

Using the C++ library I have calculated two hashes and assigned it to strings like,

std::string hash1 = "5582932E7B4443F206C202A16A4F6CDFE32AD5B9722E11542859C15D236FE35C3BFAD9";
std::string hash2 = "C782932E7B4443F205C203A16A4B6CDFE32AD4BDB23A11546859C15D236BE35C3BFAD9";

What methods do Tlsh offers to find the distance score between two hashes could any one help me with this issue.

jonjoliver commented 5 years ago

Look at timing_unittest.cpp That shows you how to do it https://github.com/trendmicro/tlsh/blob/master/test/timing_unittest.cpp

VISWESWARAN1998 commented 5 years ago

Hello thank you for your communication, I was able to see a method named "totalDiff" something like this,

int dist = t1.totalDiff(&t2);

But is used to calculate the distance between two Tlsh objects not for two hashes of Tlsh strings generated from "getHash" method.

Am I missing something could you please help me with this issue. Thank you so much!

jonjoliver commented 5 years ago
std::string hash1 = "5582932E7B4443F206C202A16A4F6CDFE32AD5B9722E11542859C15D236FE35C3BFAD9";
std::string hash2 = "C782932E7B4443F205C203A16A4B6CDFE32AD4BDB23A11546859C15D236BE35C3BFAD9";
Tlsh t1;
Tlsh t2;
int err1;
int err2;
    err1 = t1.fromTlshStr(hash1.cstr());
    err2 = t2.fromTlshStr(hash2.cstr());
    if (err1 || err2) {
          // error condition
          ...
    } else {
          int dist = t1.totalDiff(&t2);
          ...
    }
VISWESWARAN1998 commented 5 years ago

Thank you very much sir!