Skip to main content

A charset generator for CTFs

Project description

Charset Generator

Overview

This package is designed to make CTF char-by-char bruteforce simpler.

Installation

pip install charset-generator

Documentation

Charsets can be generated from string.printable using gen_charset.

If frequency_sorted is True, then it will be ordered based on frequency, with the most frequent characters appearing first.

gen_charset(regex: str, frequency_sorted: bool = False) -> str:

Characters can be produced from a generator using yielding.yield_charset.

If allow_interruptions is True, then the user can press the interrupt_key, to temporarily take over, allowing them to choose the next character. This is useful for cases where the user can predict the next character faster than it would take to bruteforce through the charset.

yielding.yield_charset(regex: str, frequency_sorted: bool = False, allow_interruptions: bool = False, interrupt_key: str = "esc") -> Generator[str, None, None]:

ai.assess_predictability and ai.predict_next_char are both highly experimental.

Together, they allow you to use OpenAI to predict the next character of a flag, given some prefix known_text.

Use these with caution.

ai.assess_predictability(
    known_text: str, openai_api_key: str, model: str = "gpt-4o-mini",
    role: str = "You are a professional CTF hacker.",
    prompt: str = (
        "You will receive the first part of a flag. Analyze it and decide how confident you are in predicting "
        "the next character with 100% accuracy. Provide a brief explanation, then on a new line output exactly "
        "'~~' followed by one of these options: 'Very confident', 'Somewhat confident', or 'Not confident'.\n"
        "Example:\n"
        "The flag starts with 'CTF{' but many characters could follow.\n"
        "~~Not confident\n"
    )
) -> str
ai.predict_next_char(
    known_text: str, openai_api_key: str, banned_chars: List[str] = [], model: str = "gpt-4o-mini",
    role: str = "You are a professional CTF hacker.",
    prompt: str = (
        "You will receive the first part of a flag. Predict the next character with no extra text. "
        "Your answer must be exactly one character. Note that flags may include leet speak or underscores.\n"
    )
) -> str

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

charset_generator-1.0.0.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

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

charset_generator-1.0.0-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file charset_generator-1.0.0.tar.gz.

File metadata

  • Download URL: charset_generator-1.0.0.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for charset_generator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ca49cfb94ceddb74f253e54c3f1b4c9b143c9e80a729201860fa5bb6f182d191
MD5 ea8884df97772817bfcb52a09cf4b523
BLAKE2b-256 98ccae76bbf29e82c1a3b8e6e43992768afdc20f2d462220fa5b7de9c5bd6ed0

See more details on using hashes here.

File details

Details for the file charset_generator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for charset_generator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aeb3a14e2c208ec6cd980fe152d6f1e544e360a9bbd6914693ead926a42a0c35
MD5 16c37689882c6ed73af3d801b4ca8914
BLAKE2b-256 fdc557149ea4923d7dd14de2b41a0c99e0554b358b1df99754abfff1287e2305

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