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
use common::{alphabet, substitute};
use common::alphabet::Alphabet;
pub fn apply(message: &str) -> String {
substitute::shift_substitution(message, |i| alphabet::STANDARD.modulo((i + 13) as isize))
.unwrap()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn with_utf8() {
let message = "Peace, Freedom and Liberty! 🗡️";
let encrypted = apply(message);
let decrypted = apply(&encrypted);
assert_eq!(decrypted, message);
}
#[test]
fn alphabet_encrypt() {
let message = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let encrypted = apply(message);
let decrypted = apply(&encrypted);
assert_eq!(decrypted, message);
}
}