Crates.io | hextool |
lib.rs | hextool |
version | 0.1.3 |
source | src |
created_at | 2023-09-20 22:10:58.375589 |
updated_at | 2023-09-22 20:59:52.298265 |
description | A simple command line tool to convert hex to string and string to hex |
homepage | https://github.com/CyR1en/hextool |
repository | https://github.com/CyR1en/hextool |
max_upload_size | |
id | 978796 |
size | 27,631 |
Simple command line tool for converting strings to hex and hex to string. Written in Rust!
This is my personal tool intended to be used for CTFs. I am aware that tools like hex
and unhex
already exist.
However, I want to strengthen my Rust skills, therefore, I decided to make my own implementation and eventually distribute it to crates.io
.
For now the only way to install hextool
command line tool is through cargo
cargo install hextool
Commandline tool to convert hex to string and string to hex
Usage: hextool <COMMAND>
Commands:
hex Change input to hex
unhex Change input from hex
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
hextool
could also be used as a library for your rust projects. You can do so by adding it to your cargo.toml
[dependencies]
hextool = { version = "version", default-features = false }
With hextool
you can use Hex
and UnHex
to convert strings from and to hex strings.
Both Hex
and UnHex
implements this trait. This trait has a function called convert
and it has the following parameters. It's important to know these parameters because it changes how the output.
fn convert(input: &str, numeric: bool, split: bool) -> String
input
- The input to convertnumeric
- If set to true, the input will be considered as a numeric value.
split
- If set to true, the output will be split in bytes.
Hex
this will separate the converted input to bytes.
aa
-> 61 61
UnHex
this will separate the converted hex to a single ascii.
6161
-> a a
use hextool::{Hex, Convert};
// Convert a string to hex
let hex = Hex::convert("hello", false, false);
println!("hello in hex: {}", hex);
// #=> "hello in hex: 68656c6c6f"
// You can also split the output in bytes
let hex = Hex::convert("hello", false, true);
println!("hello in hex: {}", hex);
// #=> "hello in hex: 68 65 6c 6c 6f"
// Convert a string with numeric flag. This will take the numerical value of the string.
// If the string is not a number, it will return an error.
let hex = Hex::convert("255", true, false);
println!("255 in hex: {}", hex);
// #=> "255 in hex: {ff}"
use hextool::{UnHex, Convert};
// Convert a hex string to a string
let unhex = UnHex::convert("68656c6c6f", false, false);
println!("68656c6c6f in string: {}", unhex);
// #=> "68656c6c6f in string: hello"
// Convert a hex string to a string with numeric flag. This will take the numerical value of the string.
let unhex = UnHex::convert("cafebabe", true, false);
println!("cafebabe in string: {}", unhex);
// #=> "cafebabe in string: 3405691582"
// If numeric is set to false, only valid strings [0-9a-f] is accepted. If the string is not valid,
// it will return the string with the invalid string highlighted to red.
let unhex = UnHex::convert("aga", true, false);
println!("{}", unhex);
// #=> "The highlighted chars can't be converted:\nag\u{1b}[31ma\u{1b}[0m."