route_cipher_encrypt

Function route_cipher_encrypt 

Source
pub fn route_cipher_encrypt(
    input: &[u8],
    key: u128,
) -> Result<Vec<u8>, &'static str>
Expand description

Encrypts an array of bytes using the route cipher.

§Arguments

  • input - The array of bytes to encrypt
  • key - The number of rails to use

§Returns

Returns a Result containing the encrypted data or an error string if encryption fails.

§Errors

  • Input must not be empty - If the input array is empty
  • Key must be greater than 0 - If the key is less than 1
  • Memory access error - It may happen if the input contains non-ASCII or multi-byte characters, which could lead to unpredictable behavior when attempting to find a position in the byte array

§Example

use cryptographic_primitives::route_cipher_encrypt;
 
let plaintext = b"Hello, world!";
let ciphertext = route_cipher_encrypt(plaintext, 3).unwrap();
 
assert_eq!(ciphertext, b"Hl r!eowl l,od ");