-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_words.rs
More file actions
55 lines (50 loc) · 2.17 KB
/
Copy pathtest_words.rs
File metadata and controls
55 lines (50 loc) · 2.17 KB
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
use four_word_networking::FourWordEncoder;
fn main() {
let encoder = FourWordEncoder::new();
// Try to encode some IP addresses to get valid words
let test_ips = vec![
(std::net::Ipv4Addr::new(192, 168, 1, 1), 8080),
(std::net::Ipv4Addr::new(10, 0, 0, 1), 3000),
(std::net::Ipv4Addr::new(127, 0, 0, 1), 9000),
(std::net::Ipv4Addr::new(172, 16, 0, 1), 5000),
(std::net::Ipv4Addr::new(192, 168, 0, 1), 8080),
(std::net::Ipv4Addr::new(10, 10, 10, 10), 3000),
(std::net::Ipv4Addr::new(172, 31, 255, 255), 9999),
(std::net::Ipv4Addr::new(192, 168, 100, 200), 7777),
(std::net::Ipv4Addr::new(8, 8, 8, 8), 53),
(std::net::Ipv4Addr::new(1, 1, 1, 1), 443),
(std::net::Ipv4Addr::new(192, 168, 2, 1), 8080),
(std::net::Ipv4Addr::new(10, 0, 1, 1), 3000),
(std::net::Ipv4Addr::new(172, 16, 1, 1), 5000),
(std::net::Ipv4Addr::new(192, 168, 3, 1), 8080),
(std::net::Ipv4Addr::new(10, 0, 2, 1), 3000),
(std::net::Ipv4Addr::new(172, 16, 2, 1), 5000),
(std::net::Ipv4Addr::new(192, 168, 4, 1), 8080),
];
for (ip, port) in test_ips {
match encoder.encode_ipv4(ip, port) {
Ok(encoding) => {
println!("Valid words for IP {}:{}", ip, port);
// Use Display trait to get the words
let words_str = format!("{}", encoding);
println!(" Words string: {}", words_str);
// Parse back to get individual words
let words: Vec<&str> = words_str.split(' ').collect();
if words.len() == 4 {
println!(
" Words array: [\"{}\", \"{}\", \"{}\", \"{}\"]",
words[0], words[1], words[2], words[3]
);
}
// Test decoding back
let result = encoder.decode_ipv4(&encoding);
if result.is_ok() {
println!(" ✓ Successfully decoded back!");
}
}
Err(e) => {
println!("Error encoding {}:{} - {:?}", ip, port, e);
}
}
}
}