I'm too lazy to commit to the latest files

This commit is contained in:
2024-08-15 23:37:34 +04:00
parent 3d896c7061
commit 62b7036933
5 changed files with 149 additions and 134 deletions

View File

@@ -6,4 +6,29 @@ use crate::{
};
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)
}