basenc - Linux


Overview

basenc is a versatile command-line utility for performing a variety of base encoding and decoding operations. These include encodings such as base64, base32, and custom encodings you define.

Syntax

basenc [options] <encode/decode> [input_file] [output_file]

Options/Flags

  • -e, --encode: Encode the input file. Default
  • -d, --decode: Decode the input file.
  • -b, --base: Specify the base encoding alphabet (2-255). Default: 64
  • -w, --wrap: Wrap encoded output to a specified number of characters per line. Default: 0 (no wrapping)
  • -p, --padding: Specify the padding character to use. Default: "="
  • --help: Display help and usage information.
  • --version: Display the version of basenc.

Examples

Encode a file using base64:

basenc -e input.txt encoded.txt

Decode a base64-encoded file:

basenc -d encoded.txt decoded.txt

Use a custom base encoding alphabet:

basenc -b 32 -e input.txt encoded.txt

Wrap encoded output to 76 characters per line:

basenc -e -w 76 input.txt encoded.txt

Common Issues

Invalid input: Ensure that the input file is valid and not empty.

Unsupported encoding: If you specify a base value outside the range 2-255, you will get an error.

Incomplete decoding: Check that the input file is correctly encoded and that you have specified the correct base value for decoding.

Integration

Pipe output to other commands:

basenc -e input.txt | gzip > compressed.gz

Use as part of a script:

#!/bin/bash
encoded=$(basenc -e input.txt)
echo "Encoded data: $encoded"
decoded=$(basenc -d $encoded)
echo "Decoded data: $decoded"

Related Commands

  • base64
  • openssl
  • uuencode/uudecode