35 lines
880 B
Rust
35 lines
880 B
Rust
use gtk4 as gtk;
|
|
|
|
use crate::{
|
|
model::{models::*, Result},
|
|
model_utils::hamming_code_seven_four::*,
|
|
};
|
|
use gtk::{prelude::*, *};
|
|
|
|
pub fn start_hamming_algorithm(input: &TextView, state: bool) -> Result<String> {
|
|
let (iter_start, iter_end) = input.buffer().bounds();
|
|
let parsed_input: String = input
|
|
.buffer()
|
|
.text(&iter_start, &iter_end, false)
|
|
.to_string()
|
|
.trim()
|
|
.parse()
|
|
.unwrap();
|
|
|
|
let operation = if !state {
|
|
HammingMode::Encrypt
|
|
} else {
|
|
HammingMode::Decrypt
|
|
};
|
|
|
|
hamming(parsed_input, operation)
|
|
}
|
|
|
|
pub fn check_correct_binary_code(prepared_input: &str, l: usize) -> (bool, bool) {
|
|
let first_condition: bool = prepared_input.len() % l == 0;
|
|
|
|
let second_condition: bool = prepared_input.chars().all(|c| c == '1' || c == '0');
|
|
|
|
(first_condition, second_condition)
|
|
}
|