hexconv 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hexconv-0.1.0/LICENSE +22 -0
- hexconv-0.1.0/MANIFEST.in +3 -0
- hexconv-0.1.0/PKG-INFO +145 -0
- hexconv-0.1.0/README.md +116 -0
- hexconv-0.1.0/pyproject.toml +46 -0
- hexconv-0.1.0/setup.cfg +4 -0
- hexconv-0.1.0/src/hexconv/__init__.py +76 -0
- hexconv-0.1.0/src/hexconv/_core.py +832 -0
- hexconv-0.1.0/src/hexconv/py.typed +1 -0
- hexconv-0.1.0/src/hexconv.egg-info/PKG-INFO +145 -0
- hexconv-0.1.0/src/hexconv.egg-info/SOURCES.txt +13 -0
- hexconv-0.1.0/src/hexconv.egg-info/dependency_links.txt +1 -0
- hexconv-0.1.0/src/hexconv.egg-info/requires.txt +5 -0
- hexconv-0.1.0/src/hexconv.egg-info/top_level.txt +1 -0
- hexconv-0.1.0/tests/test_hexconv.py +97 -0
hexconv-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hexconv contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
hexconv-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hexconv
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pythonic CTF-friendly conversions between bytes, hex, integers, arrays, and text.
|
|
5
|
+
Author: hexconv contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: ctf,hex,bytes,conversion,pwn,crypto
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest; extra == "dev"
|
|
27
|
+
Requires-Dist: twine; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# hexconv
|
|
31
|
+
|
|
32
|
+
`hexconv` is a small, dependency-free Python library for CTF-style conversions between
|
|
33
|
+
bytes, byte arrays, hex strings, hex arrays, integers, integer arrays, bytes literals,
|
|
34
|
+
binary strings, base64, and raw text.
|
|
35
|
+
|
|
36
|
+
The main idea is: explicitly state what you have, then ask for what you want.
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import hexconv as hx
|
|
40
|
+
|
|
41
|
+
hx.from_hex("dead beef").to_bytes()
|
|
42
|
+
# b'\xde\xad\xbe\xef'
|
|
43
|
+
|
|
44
|
+
hx.from_hex("dead beef").bytes
|
|
45
|
+
# b'\xde\xad\xbe\xef'
|
|
46
|
+
|
|
47
|
+
hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).to_hex()
|
|
48
|
+
# 'deadbeef'
|
|
49
|
+
|
|
50
|
+
hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).hex
|
|
51
|
+
# 'deadbeef'
|
|
52
|
+
|
|
53
|
+
hx.from_text("flag").to_hex_array(prefix=True)
|
|
54
|
+
# ['0x66', '0x6c', '0x61', '0x67']
|
|
55
|
+
|
|
56
|
+
hx.from_int(0xdeadbeef).to_bytes()
|
|
57
|
+
# b'\xde\xad\xbe\xef'
|
|
58
|
+
|
|
59
|
+
hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
|
|
60
|
+
# ['1234', '5678']
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Why explicit source helpers?
|
|
64
|
+
|
|
65
|
+
Some inputs are impossible to infer safely:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
"face"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
That could be ASCII text (`66 61 63 65`) or hex bytes (`fa ce`). So `hexconv`
|
|
72
|
+
keeps the safe path explicit:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
hx.from_text("face").to_hex()
|
|
76
|
+
# '66616365'
|
|
77
|
+
|
|
78
|
+
hx.from_hex("face").to_bytes()
|
|
79
|
+
# b'\xfa\xce'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
If you do want convenience heuristics, use `from_auto`:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
hx.from_auto("0xdeadbeef").to_int()
|
|
86
|
+
# 3735928559
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Converter API
|
|
90
|
+
|
|
91
|
+
If you prefer a reusable converter object, use marker classes:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
conv = hx.Converter(hx.BytesArray, hx.HexArray)
|
|
95
|
+
conv([0xde, 0xad, 0xbe, 0xef])
|
|
96
|
+
# ['de', 'ad', 'be', 'ef']
|
|
97
|
+
|
|
98
|
+
hx.convert("flag", from_=hx.Text, to=hx.HexString)
|
|
99
|
+
# '666c6167'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
For conversions with options, pass input and output option dictionaries:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
conv = hx.Converter(
|
|
106
|
+
hx.DecimalIntArray,
|
|
107
|
+
hx.HexArray,
|
|
108
|
+
input_options={"width": 2},
|
|
109
|
+
output_options={"width": 2, "prefix": True},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
conv([4660, 22136])
|
|
113
|
+
# ['0x1234', '0x5678']
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Supported source helpers
|
|
117
|
+
|
|
118
|
+
- `from_bytes(value)`
|
|
119
|
+
- `from_bytes_array(values)`
|
|
120
|
+
- `from_bytes_string(value)` for strings like `"b'\\xde\\xad'"`
|
|
121
|
+
- `from_hex(value)`
|
|
122
|
+
- `from_hex_array(values)`
|
|
123
|
+
- `from_hex_int(value)`
|
|
124
|
+
- `from_int(value)`
|
|
125
|
+
- `from_int_array(values, width=...)`
|
|
126
|
+
- `from_text(value)`
|
|
127
|
+
- `from_binary(value)`
|
|
128
|
+
- `from_base64(value)`
|
|
129
|
+
- `from_auto(value)`
|
|
130
|
+
|
|
131
|
+
## Common output methods
|
|
132
|
+
|
|
133
|
+
- `to_bytes()`
|
|
134
|
+
- `to_bytearray()`
|
|
135
|
+
- `to_bytes_array()`
|
|
136
|
+
- `to_bytes_string()`
|
|
137
|
+
- `to_hex(sep="", prefix=False, uppercase=False)`
|
|
138
|
+
- `to_hex_array(width=1, prefix=False, uppercase=False)`
|
|
139
|
+
- `to_hex_numbers(width=1)`
|
|
140
|
+
- `to_int(endian="big", signed=False)`
|
|
141
|
+
- `to_int_array(width=1, endian="big", signed=False)`
|
|
142
|
+
- `to_text(encoding="ascii", errors="strict")`
|
|
143
|
+
- `to_binary(sep="")`
|
|
144
|
+
- `to_base64()`
|
|
145
|
+
- `to(format_marker, **options)`
|
hexconv-0.1.0/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# hexconv
|
|
2
|
+
|
|
3
|
+
`hexconv` is a small, dependency-free Python library for CTF-style conversions between
|
|
4
|
+
bytes, byte arrays, hex strings, hex arrays, integers, integer arrays, bytes literals,
|
|
5
|
+
binary strings, base64, and raw text.
|
|
6
|
+
|
|
7
|
+
The main idea is: explicitly state what you have, then ask for what you want.
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import hexconv as hx
|
|
11
|
+
|
|
12
|
+
hx.from_hex("dead beef").to_bytes()
|
|
13
|
+
# b'\xde\xad\xbe\xef'
|
|
14
|
+
|
|
15
|
+
hx.from_hex("dead beef").bytes
|
|
16
|
+
# b'\xde\xad\xbe\xef'
|
|
17
|
+
|
|
18
|
+
hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).to_hex()
|
|
19
|
+
# 'deadbeef'
|
|
20
|
+
|
|
21
|
+
hx.from_bytes_array([0xde, 0xad, 0xbe, 0xef]).hex
|
|
22
|
+
# 'deadbeef'
|
|
23
|
+
|
|
24
|
+
hx.from_text("flag").to_hex_array(prefix=True)
|
|
25
|
+
# ['0x66', '0x6c', '0x61', '0x67']
|
|
26
|
+
|
|
27
|
+
hx.from_int(0xdeadbeef).to_bytes()
|
|
28
|
+
# b'\xde\xad\xbe\xef'
|
|
29
|
+
|
|
30
|
+
hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
|
|
31
|
+
# ['1234', '5678']
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Why explicit source helpers?
|
|
35
|
+
|
|
36
|
+
Some inputs are impossible to infer safely:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
"face"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
That could be ASCII text (`66 61 63 65`) or hex bytes (`fa ce`). So `hexconv`
|
|
43
|
+
keeps the safe path explicit:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
hx.from_text("face").to_hex()
|
|
47
|
+
# '66616365'
|
|
48
|
+
|
|
49
|
+
hx.from_hex("face").to_bytes()
|
|
50
|
+
# b'\xfa\xce'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If you do want convenience heuristics, use `from_auto`:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
hx.from_auto("0xdeadbeef").to_int()
|
|
57
|
+
# 3735928559
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Converter API
|
|
61
|
+
|
|
62
|
+
If you prefer a reusable converter object, use marker classes:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
conv = hx.Converter(hx.BytesArray, hx.HexArray)
|
|
66
|
+
conv([0xde, 0xad, 0xbe, 0xef])
|
|
67
|
+
# ['de', 'ad', 'be', 'ef']
|
|
68
|
+
|
|
69
|
+
hx.convert("flag", from_=hx.Text, to=hx.HexString)
|
|
70
|
+
# '666c6167'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For conversions with options, pass input and output option dictionaries:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
conv = hx.Converter(
|
|
77
|
+
hx.DecimalIntArray,
|
|
78
|
+
hx.HexArray,
|
|
79
|
+
input_options={"width": 2},
|
|
80
|
+
output_options={"width": 2, "prefix": True},
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
conv([4660, 22136])
|
|
84
|
+
# ['0x1234', '0x5678']
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Supported source helpers
|
|
88
|
+
|
|
89
|
+
- `from_bytes(value)`
|
|
90
|
+
- `from_bytes_array(values)`
|
|
91
|
+
- `from_bytes_string(value)` for strings like `"b'\\xde\\xad'"`
|
|
92
|
+
- `from_hex(value)`
|
|
93
|
+
- `from_hex_array(values)`
|
|
94
|
+
- `from_hex_int(value)`
|
|
95
|
+
- `from_int(value)`
|
|
96
|
+
- `from_int_array(values, width=...)`
|
|
97
|
+
- `from_text(value)`
|
|
98
|
+
- `from_binary(value)`
|
|
99
|
+
- `from_base64(value)`
|
|
100
|
+
- `from_auto(value)`
|
|
101
|
+
|
|
102
|
+
## Common output methods
|
|
103
|
+
|
|
104
|
+
- `to_bytes()`
|
|
105
|
+
- `to_bytearray()`
|
|
106
|
+
- `to_bytes_array()`
|
|
107
|
+
- `to_bytes_string()`
|
|
108
|
+
- `to_hex(sep="", prefix=False, uppercase=False)`
|
|
109
|
+
- `to_hex_array(width=1, prefix=False, uppercase=False)`
|
|
110
|
+
- `to_hex_numbers(width=1)`
|
|
111
|
+
- `to_int(endian="big", signed=False)`
|
|
112
|
+
- `to_int_array(width=1, endian="big", signed=False)`
|
|
113
|
+
- `to_text(encoding="ascii", errors="strict")`
|
|
114
|
+
- `to_binary(sep="")`
|
|
115
|
+
- `to_base64()`
|
|
116
|
+
- `to(format_marker, **options)`
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hexconv"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Pythonic CTF-friendly conversions between bytes, hex, integers, arrays, and text."
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "hexconv contributors" }]
|
|
14
|
+
keywords = ["ctf", "hex", "bytes", "conversion", "pwn", "crypto"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Security",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"build",
|
|
34
|
+
"pytest",
|
|
35
|
+
"twine",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
hexconv = ["py.typed"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
46
|
+
pythonpath = ["src"]
|
hexconv-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""CTF-friendly conversions between bytes, hex, integers, arrays, and text."""
|
|
2
|
+
|
|
3
|
+
from ._core import (
|
|
4
|
+
ASCIIText,
|
|
5
|
+
Auto,
|
|
6
|
+
Base64String,
|
|
7
|
+
BinaryString,
|
|
8
|
+
Bytes,
|
|
9
|
+
BytesArray,
|
|
10
|
+
BytesString,
|
|
11
|
+
Converter,
|
|
12
|
+
DecimalInt,
|
|
13
|
+
DecimalIntArray,
|
|
14
|
+
HexArray,
|
|
15
|
+
HexConvError,
|
|
16
|
+
HexInt,
|
|
17
|
+
HexNumbersArray,
|
|
18
|
+
HexString,
|
|
19
|
+
Int,
|
|
20
|
+
IntArray,
|
|
21
|
+
LargeHexNumber,
|
|
22
|
+
RawString,
|
|
23
|
+
Text,
|
|
24
|
+
Value,
|
|
25
|
+
convert,
|
|
26
|
+
from_auto,
|
|
27
|
+
from_base64,
|
|
28
|
+
from_binary,
|
|
29
|
+
from_bytes,
|
|
30
|
+
from_bytes_array,
|
|
31
|
+
from_bytes_string,
|
|
32
|
+
from_hex,
|
|
33
|
+
from_hex_array,
|
|
34
|
+
from_hex_int,
|
|
35
|
+
from_int,
|
|
36
|
+
from_int_array,
|
|
37
|
+
from_text,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"ASCIIText",
|
|
42
|
+
"Auto",
|
|
43
|
+
"Base64String",
|
|
44
|
+
"BinaryString",
|
|
45
|
+
"Bytes",
|
|
46
|
+
"BytesArray",
|
|
47
|
+
"BytesString",
|
|
48
|
+
"Converter",
|
|
49
|
+
"DecimalInt",
|
|
50
|
+
"DecimalIntArray",
|
|
51
|
+
"HexArray",
|
|
52
|
+
"HexConvError",
|
|
53
|
+
"HexInt",
|
|
54
|
+
"HexNumbersArray",
|
|
55
|
+
"HexString",
|
|
56
|
+
"Int",
|
|
57
|
+
"IntArray",
|
|
58
|
+
"LargeHexNumber",
|
|
59
|
+
"RawString",
|
|
60
|
+
"Text",
|
|
61
|
+
"Value",
|
|
62
|
+
"convert",
|
|
63
|
+
"from_auto",
|
|
64
|
+
"from_base64",
|
|
65
|
+
"from_binary",
|
|
66
|
+
"from_bytes",
|
|
67
|
+
"from_bytes_array",
|
|
68
|
+
"from_bytes_string",
|
|
69
|
+
"from_hex",
|
|
70
|
+
"from_hex_array",
|
|
71
|
+
"from_hex_int",
|
|
72
|
+
"from_int",
|
|
73
|
+
"from_int_array",
|
|
74
|
+
"from_text",
|
|
75
|
+
]
|
|
76
|
+
|