Metadata-Version: 2.4
Name: hexconv
Version: 0.1.0
Summary: Pythonic CTF-friendly conversions between bytes, hex, integers, arrays, and text.
Author: hexconv contributors
License-Expression: MIT
Keywords: ctf,hex,bytes,conversion,pwn,crypto
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# hexconv

`hexconv` is a small, dependency-free Python library for CTF-style conversions between
bytes, byte arrays, hex strings, hex arrays, integers, integer arrays, bytes literals,
binary strings, base64, and raw text.

The main idea is: explicitly state what you have, then ask for what you want.

```python
import hexconv as hx

hx.from_hex("dead beef").to_bytes()
# b'\xde\xad\xbe\xef'

hx.from_hex("dead beef").bytes
# b'\xde\xad\xbe\xef'

hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).to_hex()
# 'deadbeef'

hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).hex
# 'deadbeef'

hx.from_text("flag").to_hex_array(prefix=True)
# ['0x66', '0x6c', '0x61', '0x67']

hx.from_int(0xdeadbeef).to_bytes()
# b'\xde\xad\xbe\xef'

hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
# ['1234', '5678']
```

## Why explicit source helpers?

Some inputs are impossible to infer safely:

```python
"face"
```

That could be ASCII text (`66 61 63 65`) or hex bytes (`fa ce`). So `hexconv`
keeps the safe path explicit:

```python
hx.from_text("face").to_hex()
# '66616365'

hx.from_hex("face").to_bytes()
# b'\xfa\xce'
```

If you do want convenience heuristics, use `from_auto`:

```python
hx.from_auto("0xdeadbeef").to_int()
# 3735928559
```

## Converter API

If you prefer a reusable converter object, use marker classes:

```python
conv = hx.Converter(hx.BytesArray, hx.HexArray)
conv([0xde, 0xad, 0xbe, 0xef])
# ['de', 'ad', 'be', 'ef']

hx.convert("flag", from_=hx.Text, to=hx.HexString)
# '666c6167'
```

For conversions with options, pass input and output option dictionaries:

```python
conv = hx.Converter(
    hx.DecimalIntArray,
    hx.HexArray,
    input_options={"width": 2},
    output_options={"width": 2, "prefix": True},
)

conv([4660, 22136])
# ['0x1234', '0x5678']
```

## Supported source helpers

- `from_bytes(value)`
- `from_bytes_array(values)`
- `from_bytes_string(value)` for strings like `"b'\\xde\\xad'"`
- `from_hex(value)`
- `from_hex_array(values)`
- `from_hex_int(value)`
- `from_int(value)`
- `from_int_array(values, width=...)`
- `from_text(value)`
- `from_binary(value)`
- `from_base64(value)`
- `from_auto(value)`

## Common output methods

- `to_bytes()`
- `to_bytearray()`
- `to_bytes_array()`
- `to_bytes_string()`
- `to_hex(sep="", prefix=False, uppercase=False)`
- `to_hex_array(width=1, prefix=False, uppercase=False)`
- `to_hex_numbers(width=1)`
- `to_int(endian="big", signed=False)`
- `to_int_array(width=1, endian="big", signed=False)`
- `to_text(encoding="ascii", errors="strict")`
- `to_binary(sep="")`
- `to_base64()`
- `to(format_marker, **options)`
