tonhowtf/omniget · error · anyhow::Error

chave hex

Error message

chave hex: {}

What it means

In ctf/xor 'apply' mode with opts.key_hex set to true, the key is decoded from hexadecimal. If opts.key is not valid hex (odd length or non-hex characters) hex::decode fails and the tool raises 'chave hex: <hex error>'.

Solutions

  1. Provide the key as valid even-length hex (e.g. "deadbeef"), or
  2. Set key_hex = false to interpret opts.key as raw ASCII bytes
  3. Strip '0x' prefixes and stray whitespace from the key before calling run

Example fix

// before
let opts = XorOptions { mode: "apply".into(), key_hex: true, key: "secret".into(), .. };
// after
let opts = XorOptions { mode: "apply".into(), key_hex: true, key: "736563726574".into(), .. };
Defensive patterns

Strategy: validation

Validate before calling

if opts.key_hex {
    let k = opts.key.trim();
    if k.len() % 2 != 0 || !k.chars().all(|c| c.is_ascii_hexdigit()) {
        anyhow::bail!("key must be even-length hex, or set key_hex=false for ASCII");
    }
}

Type guard

fn valid_hex_key(opts: &XorOptions) -> bool {
    !opts.key_hex || (opts.key.trim().len() % 2 == 0
        && opts.key.trim().chars().all(|c| c.is_ascii_hexdigit()))
}

Prevention

When it happens

Trigger: Calling run with mode = "apply", key_hex = true, and a key string that is not pure hex of even length — e.g. an ASCII passphrase passed while key_hex is enabled.

Common situations: Using a text key like "secretkey" with key_hex left true from a previous run; odd-length key from manual entry; hidden whitespace or '0x' prefix in the key field.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/c3d0944be8aca93f. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/ctf/xor.rs:156

}

#[derive(Debug, Clone, Serialize)]
pub struct XorResult {
    pub candidates: Vec<XorCandidate>,
    pub key_sizes: Vec<(usize, f64)>,
}

pub fn run(opts: &XorOptions) -> anyhow::Result<XorResult> {
    let data = if opts.input_hex {
        hex::decode(opts.input.trim().replace([' ', '\n', ':'], ""))
            .map_err(|e| anyhow::anyhow!("hex inválido: {}", e))?
    } else {
        opts.input.as_bytes().to_vec()
    };
    Ok(match opts.mode.as_str() {
        "apply" => {
            let key = if opts.key_hex {
                hex::decode(opts.key.trim()).map_err(|e| anyhow::anyhow!("chave hex: {}", e))?
            } else {
                opts.key.as_bytes().to_vec()
            };
            let out = xor(&data, &key);
            XorResult {
                candidates: vec![XorCandidate {
                    key: opts.key.clone(),
                    key_hex: hex::encode(&key),
                    text: String::from_utf8_lossy(&out).to_string(),
                    score: 0.0,
                }],
                key_sizes: vec![],
            }
        }
        "repeating" => XorResult {
            key_sizes: guess_key_sizes(&data, opts.max_key_size, 5),
            candidates: break_repeating(&data, opts.max_key_size)
                .into_iter()

View on GitHub (pinned to 8600b91f42)