TLSH - C++ extension for Python
TLSH (Trend Micro Locality Sensitive Hash) is a fuzzy matching library. Given a byte stream with a minimum length of 50 bytes TLSH generates a hash value which can be used for similarity comparisons. Similar objects will have similar hash values which allows for the detection of similar objects by comparing their hash values. Note that the byte stream should have a sufficient amount of complexity. For example, a byte stream of identical bytes will not generate a hash value.
Usage
import tlsh
tlsh.hash(data)
Note that in default mode the data must contain at least 50 bytes to generate a hash value and that
it must have a certain amount of randomness.
If you use the "conservative" option, then the data must contain at least 256 characters.
For example, tlsh.hash(str(os.urandom(256))), should always generate a hash.
To get the hash value of a file, try tlsh.hash(open(file, 'rb').read()).
tlsh.diff(h1, h2)
tlsh.diffxlen(h1, h2)
The diffxlen function removes the file length component of the tlsh header from
the comparison. If a file with a repeating pattern is compared to a file
with only a single instance of the pattern, then the difference will be increased
if the file lenght is included. But by using the diffxlen function, the file
length will be removed from consideration.
Example
import tlsh
h1 = tlsh.hash(data)
h2 = tlsh.hash(similar_data)
score = tlsh.diff(h1, h2)
h3 = tlsh.Tlsh()
with open('file', 'rb') as f:
for buf in iter(lambda: f.read(512), b''):
h3.update(buf)
h3.final()
assert h3.diff(h) == 0
score = h3.diff(h1)
Metadata
Release files for python-tlsh 3.17.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-tlsh-3.17.0.tar.gz | 36.2 kB | Without provenance | Details for python-tlsh-3.17.0.tar.gz |
Release files / python-tlsh-3.17.0.tar.gz
| Download URL | python-tlsh-3.17.0.tar.gz |
|---|---|
| Size | 36.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
daeab966d63fd87a5f3d341301b22952f28d72a06a4c71936123c4bb7fa5ae5a
|
|
BLAKE2b-256 checksum How to use checksums |
80eec2adc0b259c23472b355065d3ee34785bb186264fbcde88cce3f0754ce48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.9
|
Security for python-tlsh 3.17.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.