[Overview][Resource strings][Constants][Types][Procedures and functions][Index] | Reference for unit 'strutils' (#rtl)

# XorEncode

Encode a string by XOR-ing its characters using characters of a given key, representing the result as hex values.

## Declaration

Source position: strutils.pp line 163

`function XorEncode(`
`const Key: String;`
`const Source: String`
`):String;`

## Arguments

`Key` |  | Key to use when encoding.
`Source` |  | String ro encode.

## Function result

Original encoded string.

## Description

XorEncode encodes the string Source by XOR-ing each character in Source with the corresponding character in Key (repeating Key as often as necessary) and representing the resulting ASCII code as a hexadecimal number (of length 2). The result is therefore twice as long as the original string, and every 2 bytes represent an ASCII code.

Feeding the resulting string with the same key Key to the XorDecode function will result in the original Source string.

This function can be used e.g. to trivially encode a password in a configuration file.

## Errors

None.

## See also

XorDecode |  | Decode a string encoded with XorEncode
XorString |  | Encode a string by XOR-ing its characters using characters of a given key.
Hex2Dec |  | Converts a hexadecimal string to a decimal value

The latest version of this document can be found at lazarus-ccr.sourceforge.net.