use crate::Traits::{BruteForce, Decrypt, Encrypt};
#[cfg(feature = "python-integration")]
use pyo3::pyclass;
#[derive(Default, Clone)]
#[cfg_attr(feature = "python-integration", pyclass)]
pub struct Affine {
pub(crate) a: usize,
pub(crate) b: usize,
}
impl Affine {
pub fn new(a: usize, b: usize) -> Self {
Self { a, b }
}
}
#[cfg(feature = "python-integration")]
mod python_integration {
use super::*;
use crate::utils::python_integration::PyBaseString;
use crate::utils::{BaseString, EncodedString, StringType};
use gmp_mpfr_sys::mpfr::inp_str;
use pyo3::prelude::*;
use std::collections::HashMap;
#[pymethods]
impl Affine {
#[new]
fn __new__(a: usize, b: usize) -> Self {
Self::new(a, b)
}
pub fn encrypt(&self, input: String) -> PyResult<PyBaseString> {
match Encrypt::encrypt(self, input.into()) {
Ok(s) => Ok(s.into()),
Err(e) => Err(pyo3::exceptions::PyException::new_err(format!("{:?}", e))),
}
}
pub fn decrypt(&self, input: String) -> PyResult<PyBaseString> {
match Decrypt::decrypt(self, input.into()) {
Ok(s) => Ok(s.into()),
Err(e) => Err(pyo3::exceptions::PyException::new_err(format!("{:?}", e))),
}
}
pub fn __str__(&self) -> PyResult<String> {
let mut s = String::new();
s.push_str(&format!("Affine Cipher\n"));
Ok(s)
}
}
}