I'm too lazy to commit to the latest files
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user