function xorCipher
xorCipher(
data: Uint8Array,
offset: number
): Uint8Array

Applies the Baichuan XOR cipher. The cipher is its own inverse, so the same call encrypts and decrypts.

Each byte is XORed with key[(offset + i) % 8] and with offset, where the key is 1f 2d 3c 4b 5a 69 78 ff and offset is the message's channel id.

Examples

Decrypt with the channel id of the message header

import { assertEquals } from "@std/assert";
import { xorCipher } from "@hertzg/reolink-api/encoding/cipher";

const encrypted = Uint8Array.of(0xd1, 0xc3, 0xf1, 0xe7);

assertEquals(new TextDecoder().decode(xorCipher(encrypted, 251)), "abcd");

Parameters

The bytes to encrypt or decrypt.

offset: number

The message's channel id, used modulo 256.

Return Type

A new array with the transformed bytes.

Usage

import { xorCipher } from "encoding/cipher.ts";