net_sender/
net_sender.rs

1use std::io::{self, Read};
2use std::net::TcpStream;
3use std::io::Write;
4use hop_core::{CompanionMatrix, Field, StreamGenerator};
5
6fn main() -> io::Result<()> {
7    // Connect to receiver
8    let mut stream = TcpStream::connect("127.0.0.1:4000")?;
9
10    // Example polynomial coefficients and state
11    let coeffs = vec![1, 2, 3];
12    let companion = CompanionMatrix::from_coeffs(&coeffs);
13    let t = StreamGenerator::build_t_from_poly(&companion, &coeffs);
14    let state = vec![Field::one(); companion.k];
15    let mut sg = StreamGenerator::new(companion, t, state);
16
17    // Read plain data from stdin
18    let mut input = Vec::new();
19    io::stdin().read_to_end(&mut input)?;
20
21    // Encode and send
22    for b in input {
23        let _mask = sg.step();
24        // very simple “encryption”: just add the mask
25        let encoded = b.wrapping_add((_mask.v & 0xFF) as u8);
26        stream.write_all(&[encoded])?;
27    }
28
29    Ok(())
30}