use gmp_mpfr_sys::mpfr::ui_sub;
use crate::Traits::{BruteForce, Decrypt, Encrypt};
#[cfg(feature = "python-integration")]
use pyo3::pyclass;
#[cfg(feature = "python-integration")]
use pyo3_helper_macros::py3_bind_pub;
use crate::utils::{cyclic_left_shift, mod_add};
#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "python-integration", pyclass)]
pub struct Vahf {
main_key: Vec<usize>,
pub(crate) keys: Vec<Vec<usize>>,
}
#[cfg_attr(feature = "python-integration", py3_bind_pub)]
impl Vahf {
const S: [u32; 6] = [3, 5, 7, 11, 13, 17];
pub fn new(k1: usize, k2: usize, k3: usize) -> Self {
let mut vahf = Self {
main_key: vec![k1, k2, k3],
keys: Vec::new()
};
vahf.generate_keys();
vahf
}
fn generate_keys(&mut self) {
let shifts = &Self::S[..3]; let k0 = vec![
self.main_key[2], mod_add(self.main_key[0], self.main_key[1]), self.main_key[1], mod_add(self.main_key[1], self.main_key[2]), self.main_key[0], mod_add(self.main_key[0], self.main_key[2]), ];
self.keys = shifts.iter().map(|&shift| {
let shifted = cyclic_left_shift(&k0, shift as usize); shifted
}).collect();
}
pub fn get_debug_info(&self) -> String {
let mut s = String::new();
s.push_str(&"Vahf Cipher\n".to_string());
s.push_str(&format!("Main Key: {:?}\n", self.main_key));
s.push_str(&format!("Keys: {:?}\n", self.keys));
s
}
}