merge stable version #2
|
@ -18,27 +18,25 @@ static SYNDROMES: LazyLock<HashMap<usize, (bool, bool, bool)>> = LazyLock::new(|
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String, String> {
|
pub fn hamming(raw_input: String, mode: HammingMode) -> Result<String> {
|
||||||
let length_of_code: usize = mode.clone() as usize;
|
let length_of_code: usize = mode.clone() as usize;
|
||||||
|
|
||||||
let prepared_input: String = processing_input(&raw_input);
|
let prepared_input: String = processing_input(&raw_input);
|
||||||
|
|
||||||
let (fc, sc): (bool, bool) =
|
let (first_condition, second_condition): (bool, bool) =
|
||||||
check_correct_binary_code(&raw_input, &prepared_input, length_of_code);
|
check_correct_binary_code(&raw_input, &prepared_input, length_of_code);
|
||||||
|
|
||||||
if !fc || !sc {
|
if raw_input.is_empty() {
|
||||||
Err("Ошибка. Проверьте корректность ввода.".to_string())
|
Err("Введите код.".into())
|
||||||
|
} else if !first_condition || !second_condition {
|
||||||
|
Err("Проверьте корректность ввода.".into())
|
||||||
} else {
|
} else {
|
||||||
let mut data: String = String::new();
|
|
||||||
|
|
||||||
let prepared_data: Vec<u8> = from_string_to_vec_bits(prepared_input);
|
let prepared_data: Vec<u8> = from_string_to_vec_bits(prepared_input);
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
HammingMode::Encrypt => hamming_encrypt_data(&prepared_data, &mut data, length_of_code),
|
HammingMode::Encrypt => Ok(hamming_encrypt_data(&prepared_data, length_of_code)),
|
||||||
HammingMode::Decrypt => hamming_decrypt_data(&prepared_data, &mut data, length_of_code),
|
HammingMode::Decrypt => Ok(hamming_decrypt_data(&prepared_data, length_of_code)),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue