Skip to main content

Simple text encoding type classifier

Project description

whatenc

PyPI License

Text encoding type classifier.

whatenc is a command-line tool that uses a gradient-boosted tree classifier to detect the encoding of a given string or file.

The model is trained on text samples from the English, Greek, Russian, Hebrew, and Arabic Wikipedia corpora, chosen to represent a diverse set of writing systems (Latin, Greek, Cyrillic, Hebrew, and Arabic scripts). Each line is encoded using multiple encoding schemes to generate labeled examples.

How It Works

whatenc applies a feature-based approach to characterize text, then feeds these features into a gradient-boosted decision tree model to classify the encoding.

Feature Extraction

Each input string is converted into a feature vector describing its statistical properties.

Features include:

Feature Description
Length (n) Number of characters in the input
n % 4 Useful for identifying base-N encodings
Printable Ratio Fraction of characters in string.printable
Alphabetic / Digit Ratios Ratio of letters and digits to total length
Padding Ratio (=) Common in Base64/32 encodings
Compressibility Ratio of compressed to raw byte length
Shannon Entropy Measure of randomness in character distribution
English Letter Correlation Correlation between letter frequencies and English letter frequency distribution
Stopword Ratio Fraction of English stopwords

Supported Encodings

whatenc currently recognizes the following formats and transformations:

Category Encodings
Base encodings base32, base64, base85, hex, url
Text ciphers morse
Compression gzip64
Hash digests md5, sha1, sha224, sha256, sha384, sha512

Installation

You can install whatenc using pipx:

pipx install whatenc

Usage

whatenc hello
whatenc samples.txt

Examples

[+] input: ZW5jb2RlIHRvIGJhc2U2NCBmb3JtYXQ=
   [~] top guess   = base64
      [=] base64   = 0.875
      [=] base32   = 0.101
      [=] gzip64   = 0.019

[+] input: hi
   [~] top guess   = plain
      [=] plain    = 0.772
      [=] base64   = 0.081
      [=] base32   = 0.075

[+] input: bfa99df33b137bc8fb5f5407d7e58da8
   [~] top guess   = md5
      [=] md5      = 1.000
      [=] sha1     = 0.000
      [=] url      = 0.000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatenc-0.4.0.tar.gz (83.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatenc-0.4.0-py3-none-any.whl (83.8 kB view details)

Uploaded Python 3

File details

Details for the file whatenc-0.4.0.tar.gz.

File metadata

  • Download URL: whatenc-0.4.0.tar.gz
  • Upload date:
  • Size: 83.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for whatenc-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7444754b1d550ecebe3a223aba1dbef1c1f4efac628c0d1520cbcd50a2cf0e7c
MD5 1126ab8fd4ac2eb61872c5e49b8c252e
BLAKE2b-256 01b3ad6eac91e2e81e9cc9ff67e65278f35532eeb3d0b0018798747e60be4b6e

See more details on using hashes here.

File details

Details for the file whatenc-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: whatenc-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 83.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for whatenc-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d45d81944d3826d70b16c6ce85fd34c944d4d27f14ae7785d7892c20b63c298
MD5 1752ad133035591beb33cc253018499f
BLAKE2b-256 f62a1c484c7ca54d21b2b453aae964a886d1f59b1fb70b6190cd8292baf159b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page