chore: Merge newest dev to get most recent changes
This commit is contained in:
commit
a6571e43af
1769 changed files with 398681 additions and 20 deletions
|
|
@ -1,15 +1,13 @@
|
|||
use std::{str::Bytes, string};
|
||||
|
||||
use crate::utils::poly::{self, block_2_number, get_coefficients};
|
||||
use crate::utils::poly::{b64_2_num, get_coefficients};
|
||||
use anyhow::Result;
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn block2poly(val: &Value) -> Result<Vec<u8>> {
|
||||
// Convert JSON data in to a u128
|
||||
// TODO: Transfer decoding into own function?
|
||||
let string: String = serde_json::from_value(val["block"].clone())?;
|
||||
let number: u128 = block_2_number(string)?;
|
||||
|
||||
let number = b64_2_num(&string)?;
|
||||
|
||||
let coefficients: Vec<u8> = get_coefficients(number);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::Result;
|
|||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::utils::poly::{block_2_number, coefficient_to_binary};
|
||||
use crate::utils::poly::{b64_2_num, coefficient_to_binary};
|
||||
|
||||
pub fn gfmul(args: &Value) -> Result<String> {
|
||||
eprintln!("{args}");
|
||||
|
|
@ -11,8 +11,8 @@ pub fn gfmul(args: &Value) -> Result<String> {
|
|||
let red_poly_num: u128 = coefficient_to_binary(reduction_polynomial_coeffs);
|
||||
//eprintln!("{:?}", serde_json::from_value(args["a"].clone())?);
|
||||
|
||||
let mut poly1: u128 = block_2_number(serde_json::from_value(args["a"].clone())?)?;
|
||||
let poly2: u128 = block_2_number(serde_json::from_value(args["b"].clone())?)?;
|
||||
let mut poly1: u128 = b64_2_num(&serde_json::from_value(args["a"].clone())?)?;
|
||||
let poly2: u128 = b64_2_num(&serde_json::from_value(args["b"].clone())?)?;
|
||||
eprintln!("poly1 is: {}", poly1);
|
||||
eprintln!("poly2 is: {}", poly2);
|
||||
/* Begin of magic algorithm
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod block2poly;
|
||||
pub mod gfmul;
|
||||
pub mod poly2block;
|
||||
pub mod sea128;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::utils::poly::{self, coefficient_to_binary};
|
||||
use crate::utils::poly::{self};
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
|
|
|
|||
61
src/tasks/tasks01/sea128.rs
Normal file
61
src/tasks/tasks01/sea128.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::utils::ciphers::{sea_128_decrypt, sea_128_encrypt};
|
||||
|
||||
pub fn sea128(args: &Value) -> Result<String> {
|
||||
let key_string: String = serde_json::from_value(args["key"].clone())?;
|
||||
//let key: &[u8] = b64_2_num(key_string)?.to_ne_bytes();
|
||||
let key = BASE64_STANDARD.decode(key_string)?;
|
||||
//eprintln!("{:?}", key);
|
||||
let input_string: String = serde_json::from_value(args["input"].clone())?;
|
||||
//let plaintexts: &[u8] = &b64_2_num(plaintexts_string)?.to_ne_bytes();
|
||||
let input = BASE64_STANDARD.decode(input_string)?;
|
||||
let xor_val: u128 = 0xc0ffeec0ffeec0ffeec0ffeec0ffee11;
|
||||
|
||||
let mode: String = serde_json::from_value(args["mode"].clone())?;
|
||||
match mode.as_str() {
|
||||
"encrypt" => {
|
||||
//eprintln!("{:?}", plaintexts);
|
||||
|
||||
let output = BASE64_STANDARD.encode(sea_128_encrypt(&key, &input)?);
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
"decrypt" => {
|
||||
let output = BASE64_STANDARD.encode(sea_128_decrypt(&key, &input)?);
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
_ => Err(anyhow!("Failure. no valid mode detected")),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use anyhow::Result;
|
||||
use serde_json::json;
|
||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_sea128_encrypt() -> Result<()> {
|
||||
let args = json!({"mode" : "encrypt", "key" : "istDASeincoolerKEYrofg==", "input" : "yv66vvrO263eyviIiDNEVQ=="});
|
||||
|
||||
assert_eq!(sea128(&args)?, "D5FDo3iVBoBN9gVi9/MSKQ==");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sea128_decrypt() -> Result<()> {
|
||||
let args = json!({"mode" : "decrypt", "key" : "istDASeincoolerKEYrofg==", "input" : "D5FDo3iVBoBN9gVi9/MSKQ=="});
|
||||
|
||||
assert_eq!(sea128(&args)?, "yv66vvrO263eyviIiDNEVQ==");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue