> For the complete documentation index, see [llms.txt](https://docs.monarchlinux.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monarchlinux.com/basics/shell-aliases/conversions-and-encodings.md).

# Conversions and encodings

See [Shell aliases and functions](https://docs.monarchlinux.com/basics/shell-aliases.md) for command discovery and personal overrides.

## Input and output

The new converter functions accept exactly one text argument or, when no argument is given, read stdin. An empty argument means empty input. Multiple arguments are rejected instead of joined automatically. A leading dash is literal input, not an option.

These functions preserve input newlines and add none of their own. Use `printf %s` instead of `echo` when a trailing newline is unwanted. Pipe binary data through stdin: shell arguments and command substitutions cannot preserve every byte. Invalid input fails without partial converted output. Each call buffers its input; use dedicated streaming tools for large files.

Python 3 is required. The GNU Base64 aliases described below retain their original interface rather than using this text-argument contract.

## Base64

`b64url` encodes URL-safe Base64 with `-` and `_`, without padding. `b64urld` accepts correctly padded or unpadded input and ASCII whitespace. Invalid alphabets, lengths and padding fail.

```bash
b64url 'hello?'
printf %s 'aGVsbG8_' | b64urld
```

`b64e` and `b64d` are GNU Base64 aliases. They accept options and file paths, not a literal text argument to convert. `b64e` disables line wrapping.

```bash
printf %s 'hello' | b64e
printf %s 'aGVsbG8=' | b64d
b64e './file with spaces.bin'
```

## URL components

`urlencode` percent-encodes bytes, leaving only RFC 3986 unreserved characters unchanged. Spaces become `%20`. `urldecode` preserves a literal `+` rather than turning it into a space and rejects malformed percent escapes.

These operate on URL components, not complete URLs or HTML form bodies.

```bash
urlencode 'a+b / café'
urldecode 'a%2Bb%20%2F%20caf%C3%A9'
```

## Hexadecimal

`toHex` produces lowercase hexadecimal. `fromHex` decodes hexadecimal and accepts ASCII whitespace, but not `0x` prefixes or `\xNN` notation.

```bash
toHex 'hello'
fromHex '68 65 6c 6c 6f'
printf '\000\377\n' | toHex | fromHex | xxd
```

## UTF-16LE

`utf16le` converts UTF-8 text to UTF-16LE without adding a byte-order mark. `utf16to8` reverses the conversion and preserves an explicit leading mark as a character. Both reject invalid text rather than replacing characters.

```bash
printf %s 'hello 🌍' | utf16le | utf16to8
```

## NT hashes

`nthash` computes the lowercase MD4 digest of UTF-16LE text supplied as UTF-8. It requires OpenSSL's legacy MD4 provider. This is for interoperability with legacy password hashes, not a recommendation for password storage.

Keep real passwords out of shell history and process arguments. Supply them through stdin, without unintentionally adding a newline. This public test vector is not a real password:

```bash
printf %s 'Password1' | nthash
# 64f12cddaa88057e06a81b54e73b949b
```
