ADDED: models and controllers for page "signal reducing"\n TODO: done table for page "signal reducing"
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{controller::view_utils::input_utils::*, model::model::*};
|
||||
use crate::{
|
||||
controller::view_utils::{hamming_code_input_utils::*, input_utils::*},
|
||||
model::model::*,
|
||||
};
|
||||
|
||||
/// **Синдромы**
|
||||
///
|
||||
@@ -23,7 +26,8 @@ pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String> {
|
||||
|
||||
let prepared_input: String = processing_input(&raw_input);
|
||||
|
||||
let (fc, sc) = check_correct_input(&raw_input, &prepared_input, length_of_code);
|
||||
let (fc, sc): (bool, bool) =
|
||||
check_correct_binary_code(&raw_input, &prepared_input, length_of_code);
|
||||
|
||||
if !fc || !sc {
|
||||
Err("Ошибка. Проверьте корректность ввода.".to_string())
|
||||
@@ -45,7 +49,7 @@ pub fn hamming_encrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
|
||||
let mut i: usize = length_of_code;
|
||||
|
||||
while i <= data.len() {
|
||||
let data_bits = &data[i - length_of_code..i];
|
||||
let data_bits: &[u8] = &data[i - length_of_code..i];
|
||||
let (check_bit_1, check_bit_2, check_bit_3) = (
|
||||
data_bits[0] ^ data_bits[1] ^ data_bits[3],
|
||||
data_bits[0] ^ data_bits[2] ^ data_bits[3],
|
||||
@@ -87,30 +91,32 @@ pub fn hamming_decrypt_data(data: &Vec<u8>, result_string: &mut String, length_o
|
||||
general_length += length_of_code;
|
||||
continue;
|
||||
} else {
|
||||
let error_position = syndromes
|
||||
let error_position: &usize = syndromes
|
||||
.iter()
|
||||
.find(move |&(&_error_position, &error)| error == checked_bits)
|
||||
.unwrap()
|
||||
.0;
|
||||
|
||||
let correctly_code: Vec<u8> = data_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, bit)| {
|
||||
if index == error_position - 1 {
|
||||
(*bit == 0u8).into()
|
||||
} else {
|
||||
*bit
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let uncorrect_code: String = from_vec_bits_to_string(&data_bits);
|
||||
let correct_code: String = from_vec_bits_to_string(
|
||||
data_bits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, &bit)| {
|
||||
if index == error_position - 1 {
|
||||
(bit == 0u8).into()
|
||||
} else {
|
||||
bit
|
||||
}
|
||||
})
|
||||
.collect::<Vec<u8>>()
|
||||
.as_slice(),
|
||||
);
|
||||
|
||||
let error = format!(
|
||||
"Ошибка в коде {} {:?}, позиция ошибки {}, корректный код: {:?}; \n",
|
||||
"Ошибка в коде {} [{uncorrect_code}], позиция ошибки {}, корректный код: [{correct_code}]; \n",
|
||||
general_length / 7,
|
||||
&data_bits,
|
||||
error_position,
|
||||
correctly_code
|
||||
error_position
|
||||
);
|
||||
|
||||
errors.push_str(error.as_str());
|
||||
|
||||
Reference in New Issue
Block a user