72 lines
1.7 KiB
Rust
72 lines
1.7 KiB
Rust
pub mod input_utils_module {
|
|
|
|
use gtk4 as gtk;
|
|
|
|
use std::ops::Deref;
|
|
use gtk::{*, prelude::*};
|
|
use bitvec::{order::Lsb0, view::AsBits};
|
|
|
|
use crate::{
|
|
model::model::model_module::*,
|
|
model_utils::hamming_code_seven_four::hamming_code::*
|
|
};
|
|
|
|
pub fn parse_input(input : &TextView, output : &TextView, mode: bool) -> (){
|
|
|
|
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 mode == false {
|
|
HammingMode::Encrypt
|
|
} else {
|
|
HammingMode::Decrypt
|
|
};
|
|
|
|
match hamming(parsed_input, operation) {
|
|
Ok(res) => output.buffer().set_text(res.trim_end()),
|
|
Err(rej) => output.buffer().set_text(rej.as_str()),
|
|
}
|
|
|
|
}
|
|
|
|
pub fn processing_input(input : &String) -> String {
|
|
|
|
input
|
|
.split_ascii_whitespace()
|
|
.filter(|&x| {
|
|
x != ""
|
|
})
|
|
.fold(String::new(), |c: String, n: &str| { c + n })
|
|
|
|
}
|
|
|
|
pub fn check_correct_input(input: &String, prepared_input: &String, l: usize) -> (bool, bool){
|
|
|
|
let first_condition = input
|
|
.chars()
|
|
.all(|c| {c == '1' || c == '0' || c == ' '});
|
|
|
|
let second_condition = prepared_input.len() % l == 0;
|
|
|
|
(first_condition, second_condition)
|
|
|
|
}
|
|
|
|
pub fn from_string_to_vec_bits(raw_data: String) -> Vec<u8>{
|
|
|
|
raw_data
|
|
.as_bits::<Lsb0>()
|
|
.iter()
|
|
.step_by(8)
|
|
.map(|x| *x.deref() as u8)
|
|
.collect()
|
|
|
|
}
|
|
|
|
} |