vraiment la merde

This commit is contained in:
2026-02-13 17:13:11 +01:00
parent 8c2abd902c
commit b343675fa7
4 changed files with 41 additions and 5 deletions

View File

@ -35,7 +35,7 @@ impl<'a> BitFlipDecoder<'a> {
} }
} }
println!("poid syndome: {s_w}"); // println!("poid syndome: {s_w}");
// Aucune erreurs // Aucune erreurs
if s_w == 0 { if s_w == 0 {
return Some(curr_bits); return Some(curr_bits);

View File

@ -7,6 +7,7 @@ mod encoder;
mod matrix; mod matrix;
mod simulation; mod simulation;
mod tanner; mod tanner;
mod utils;
use analysis::{AnalysisConfig, Analyzer, DecoderAlgorithm}; use analysis::{AnalysisConfig, Analyzer, DecoderAlgorithm};
@ -28,5 +29,6 @@ fn main() {
// let res = Analyzer::run_batch(config); // let res = Analyzer::run_batch(config);
// Analyzer::save_csv(&res, "ldpc_analysis_results.csv"); // Analyzer::save_csv(&res, "ldpc_analysis_results.csv");
simulation::run_simulation(300, 3, 6, 0.012); let message = "Je";
simulation::run_simulation(message, 3, 6, 0.02);
} }

View File

@ -6,12 +6,15 @@ use crate::code::{self, LdpcCode};
use crate::construction::random::{generate_random_h, generate_random_h_for_k}; use crate::construction::random::{generate_random_h, generate_random_h_for_k};
use crate::decoder::bit_flip::BitFlipDecoder; use crate::decoder::bit_flip::BitFlipDecoder;
use crate::encoder::dense::DenseEncoder; use crate::encoder::dense::DenseEncoder;
use crate::utils;
use rand::{Rng, RngExt}; use rand::{Rng, RngExt};
pub fn run_simulation(k: usize, wc: usize, wr: usize, error_prob: f64) { pub fn run_simulation(text: &str, wc: usize, wr: usize, error_prob: f64) {
let mut message_bits = utils::string_to_bits(text);
let k = message_bits.len();
println!( println!(
"\nSimulation LDPC : k = {} bits, wc = {}, wr = {}, p = {:.2}", "\nSimulation LDPC : k = {} bits, wc = {}, wr = {}, p = {:.2}, text : {}",
k, wc, wr, error_prob k, wc, wr, error_prob, text
); );
println!("Construction"); println!("Construction");
@ -68,17 +71,22 @@ pub fn run_simulation(k: usize, wc: usize, wr: usize, error_prob: f64) {
match decoder.decode(&received, max_iter) { match decoder.decode(&received, max_iter) {
Some(decoded) => { Some(decoded) => {
let decoded_message = &decoded[0..encoder.k];
let res_text = utils::bits_to_string(decoded_message);
if decoded == codeword { if decoded == codeword {
println!(" -> Réussite"); println!(" -> Réussite");
} else { } else {
println!(" -> Echec : le decoder a convergé vers un mauvais codeword"); println!(" -> Echec : le decoder a convergé vers un mauvais codeword");
} }
println!(" -> Texte recu : {}", res_text);
} }
None => { None => {
let failed_text = utils::bits_to_string(&received[0..encoder.k]);
println!( println!(
" -> Echec : impossible decorriger après {} itérations", " -> Echec : impossible decorriger après {} itérations",
max_iter max_iter
); );
println!(" -> Texte recu : {}", failed_text);
} }
} }
} }

26
Code/ldpc/src/utils.rs Normal file
View File

@ -0,0 +1,26 @@
pub fn string_to_bits(s: &str) -> Vec<u8> {
let mut bits = Vec::new();
for byte in s.as_bytes() {
for i in (0..8).rev() {
bits.push((byte >> i) & 1);
}
}
bits
}
pub fn bits_to_string(bits: &[u8]) -> String {
let mut bytes = Vec::new();
for chunk in bits.chunks(8) {
if chunk.len() < 8 {
break;
}
let mut byte = 0u8;
for (i, &bit) in chunk.iter().enumerate() {
if bit == 1 {
byte |= 1 << (7 - i);
}
}
bytes.push(byte);
}
String::from_utf8_lossy(&bytes).into_owned()
}