1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/// Encrypts a string using the affine cipher.
///
/// Each byte of the input is transformed using the formula:
///
/// ```text
/// E(x) = a ยท x + b mod 256
/// ```
///
/// # Arguments
///
/// * `x` - Plaintext to encrypt
/// * `a` - Multiplicative key. Must be odd (coprimo con 256) to allow decryption.
/// * `b` - Additive key
///
/// # Returns
///
/// * `Ok(String)` - Encrypted ciphertext
/// * `Err(FromUtf8Error)` - If the resulting bytes are not valid UTF-8
///
/// # Examples
///
/// ```
/// use cryptograph::cryptography::affine::encrypt::affine_encrypt;
/// use cryptograph::cryptography::affine::decrypt::affine_decrypt;
///
/// let encrypted = affine_encrypt("hola", 3, 7).unwrap();
/// let decrypted = affine_decrypt(&encrypted, 3, 7).unwrap();
/// assert_eq!(decrypted, "hola");
/// ```