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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use crate::{
context::{PivotByLineContext, PivotByRawLineContext},
impl_complex_decoder, impl_complex_encoder,
method::{line_extend, random_whitespace, trailing_unicode, Method},
};
pub struct ELUVMethod {
methods: Vec<Box<dyn Method<PivotByLineContext, PivotByRawLineContext>>>,
}
impl ELUVMethod {
fn new() -> Self {
ELUVMethod {
methods: vec![
Box::new(random_whitespace::RandomWhitespaceMethod::default()),
Box::new(line_extend::LineExtendMethod::default()),
Box::new(trailing_unicode::TrailingUnicodeMethod::default()),
],
}
}
}
impl Default for ELUVMethod {
fn default() -> Self {
Self::new()
}
}
impl_complex_encoder!(ELUVMethod, PivotByLineContext);
impl_complex_decoder!(ELUVMethod, PivotByRawLineContext);
impl Method<PivotByLineContext, PivotByRawLineContext> for ELUVMethod {}
#[allow(unused_imports)]
mod test {
use std::error::Error;
use crate::{binary::BitIterator, cli::encoder::EncodeSubCommand, context::{PivotByLineContext, PivotByRawLineContext}, decoder::Decoder, encoder::Encoder};
use super::ELUVMethod;
#[test]
fn encodes_text_data() -> Result<(), Box<dyn Error>> {
let cover_input = "a b c ".repeat(5);
let data_input = "abc";
let pivot: usize = 3;
let mut data_iterator = BitIterator::new(&data_input.as_bytes());
let method = ELUVMethod::default();
let mut context = PivotByLineContext::new(&cover_input, pivot);
let stego_text = method.encode(&mut context, &mut data_iterator, None)?;
assert_eq!(
&stego_text,
"a b c\u{2028}\na b\u{2062}\nc a\u{200b}\nb c a\u{2028}\nb c\na b\nc \n"
);
Ok(())
}
#[test]
fn encodes_binary_data() -> Result<(), Box<dyn Error>> {
let cover_input = "a b c ".repeat(6);
let data_input: Vec<u8> = vec![0b11101010, 0b10000011, 0b01011110];
let pivot: usize = 3;
let mut data_iterator = BitIterator::new(&data_input);
let method = ELUVMethod::default();
let mut context = PivotByLineContext::new(&cover_input, pivot);
let stego_text = method.encode(&mut context, &mut data_iterator, None)?;
assert_eq!(
&stego_text,
"a b c\u{205f}\na b c\na b c\u{200a}\na b c\na b\nc a\nb c \n"
);
Ok(())
}
#[test]
fn decodes_binary_data() -> Result<(), Box<dyn Error>> {
let stego_text = "a bc\na bcd \na b d\u{205f}\n";
let pivot: usize = 4;
let method = ELUVMethod::default();
let mut context = PivotByRawLineContext::new(&stego_text, pivot);
let secret_data = method.decode(&mut context, None)?;
assert_eq!(&secret_data, &[0b10_00000_0, 0b1_00001_11, 0b10101_000]);
Ok(())
}
#[test]
fn decodes_zeroes_if_no_data_encoded() -> Result<(), Box<dyn Error>> {
let stego_text = "a\n".repeat(5);
let pivot: usize = 4;
let method = ELUVMethod::default();
let mut context = PivotByRawLineContext::new(&stego_text, pivot);
let secret_data = method.decode(&mut context, None)?;
assert_eq!(&secret_data, &[0, 0, 0, 0, 0]);
Ok(())
}
}