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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use ;
/// Encrypts and decrypts a message using bitwise XOR with a seed (stream cipher).
///
/// Since XOR is symmetric, the same function serves for both encryption and decryption.
///
/// # Arguments
/// * `x` - Message in bits to encrypt/decrypt
/// * `seed` - Keystream of the same length as `x`
///
/// # Panics
/// If `x` and `seed` have different lengths.
///
/// # Example
/// ```
/// use cryptograph::cryptography::streams_ciphers::encrypt::stream_cipher_crypt;
///
/// let message = vec![true, false, true];
/// let seed = vec![true, true, false];
/// let cipher = stream_cipher_crypt(message.clone(), seed.clone());
/// let original = stream_cipher_crypt(cipher, seed);
/// assert_eq!(original, message);
/// ```
/// Lazy version of [`stream_cipher_encrypt`] that returns a [`Stream`] of bits.
///
/// Unlike the synchronous version, it does not allocate the output `Vec` —
/// each bit is computed only when the stream is consumed.
///
/// # Arguments
/// * `x` - Message in bits to encrypt/decrypt
/// * `seed` - Keystream of the same length as `x`
///
/// # Panics
/// If `x` and `seed` have different lengths.
///
/// # Example
/// ```
/// use futures::StreamExt;
/// use cryptograph::cryptography::streams_ciphers::encrypt::fut_stream_cipher_encrypt;
///
/// tokio_test::block_on(async {
/// let message = vec![true, false, true];
/// let seed = vec![true, true, false];
/// let mut stream = fut_stream_cipher_encrypt(message, seed);
///
/// while let Some(bit) = stream.next().await {
/// println!("{}", bit);
/// }
/// });
/// ```