Skip to main content

hex_encode

Function hex_encode 

Source
pub fn hex_encode(input: &str) -> String
Expand description

Encodes text to hexadecimal representation (lowercase).

Converts each byte to a two-character lowercase hexadecimal string. The output contains only characters 0-9 and a-f. This is a common encoding format for binary data and raw byte representations.

§Use Cases

  • Binary Data: Display binary content as readable hex
  • Debugging: View exact byte values in strings
  • Red Team: Encode shellcode or binary payloads
  • Cryptography: Display hash values and signatures

§Examples

use redstr::hex_encode;

assert_eq!(hex_encode("test"), "74657374");
assert_eq!(hex_encode("AB"), "4142");
assert_eq!(hex_encode("hello"), "68656c6c6f");

// Encode shellcode
let shellcode = vec![0x90, 0x90, 0xc3]; // NOP NOP RET
// Would encode to: "9090c3"