A lightweight command-line utility suite for encoding and decoding hexadecimal data, written in Go.
  • Go 79.6%
  • Makefile 20.4%
Find a file
2026-06-13 00:39:45 -03:00
filter_reader.go ref: improved to 1 binary, highly based on base64 2026-06-13 00:35:54 -03:00
go.mod ref: improved to 1 binary, highly based on base64 2026-06-13 00:35:54 -03:00
go.sum ref: improved to 1 binary, highly based on base64 2026-06-13 00:35:54 -03:00
LICENSE docs: LICENSE 2026-06-08 22:18:45 -03:00
main.go ref: improved to 1 binary, highly based on base64 2026-06-13 00:35:54 -03:00
Makefile fix: right name in Makefile 2026-06-13 00:38:36 -03:00
README.md docs: fixing author name to lowercase 2026-06-13 00:39:45 -03:00

CodeHex

A lightweight command-line utility for encoding and decoding hexadecimal data, written in Go.

codehex can encode raw data to hexadecimal or decode hexadecimal back to its original binary form. It works with files, standard input, and standard output, making it suitable for shell pipelines and file processing.

Features

  • Encode data to hexadecimal
  • Decode hexadecimal back to binary data
  • Read from files or standard input
  • Write to standard output
  • GNU-style command-line interface
  • Streaming implementation suitable for large files
  • No external runtime dependencies

Installation

From Source

git clone https://github.com/robogg133/codehex.git
cd codehex

make

Using Go Install

go install git.servidordomal.lol/robogg133/codehex@latest

Usage

codehex [OPTION]... [FILE]

Encode or decode FILE, or standard input, to standard output.

With no FILE, or when FILE is -, read standard input.

Options

Option Description
-d, --decode Decode hexadecimal input
--version Display version information and exit
--help Display help information

Examples

Encode Standard Input

echo "Hello World" | codehex

Output:

48656c6c6f20576f726c640a

Decode Standard Input

echo "48656c6c6f20576f726c640a" | codehex --decode

Output:

Hello World

Encode a File

codehex document.txt

Decode a File

codehex --decode document.hex

Explicitly Read From Standard Input

codehex -

Save Encoded Output

codehex image.png > image.hex

Restore Original File

codehex --decode image.hex > image.png

Version Information

Display build information:

codehex --version

Example output:

codehex version a1b2c3d (CommitID: a1b2c3d)

How It Works

Encoding Mode

By default, codehex reads raw bytes from the input source and writes hexadecimal text to standard output.

Binary Data
     ↓
 Hex Encoding
     ↓
Hexadecimal Text

Decoding Mode

When --decode is specified, codehex reads hexadecimal text and writes the decoded binary data.

Hexadecimal Text
        ↓
  Hex Decoding
        ↓
   Binary Data

Error Handling

The program exits with an error if:

  • The input file cannot be opened.
  • Invalid hexadecimal data is supplied in decode mode.
  • An I/O error occurs while reading or writing data.

Examples with Pipes

Encode:

cat file.txt | codehex

Decode:

cat file.hex | codehex -d

Multiple commands:

curl https://example.com/file.bin | codehex > file.hex
cat file.hex | codehex -d > restored.bin

Performance

The application processes data using streams (io.Copy), allowing it to efficiently handle files of virtually any size without loading them entirely into memory.

License

MIT License

Author

robogg133

Acknowledgments

  • Go standard library encoding/hex
  • Unix philosophy of small tools that do one thing well