Poly2Block; Block2Poly; SEA128 tasks working #2

Merged
0xalivecow merged 26 commits from dev into main 2024-10-23 15:21:06 +00:00
3 changed files with 66 additions and 5 deletions
Showing only changes of commit ba3975e7fd - Show all commits

16
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<executable file>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

View file

@ -1,7 +1,52 @@
use std::str::Bytes;
use crate::utils::poly;
use base64::prelude::*;
fn block2poly(block: String) {
let num_block: u128 = BASE64_STANDARD.decode(block).unwrap().into();
let coefficients = poly::get_bit_indices_from_byte();
fn block2poly(block: &str) -> Vec<u8> {
// Convert JSON data in to a u128
let decoded: Vec<u8> = BASE64_STANDARD.decode(block).unwrap();
let mut bytes: [u8; 16] = [0u8; 16];
bytes.copy_from_slice(&decoded);
let number: u128 = <u128>::from_ne_bytes(bytes);
let mut coefficients: Vec<u8> = vec![];
for shift in 0..128 {
//println!("{:?}", ((num >> shift) & 1));
if (((number >> shift) & 1) == 1) {
println!("Shift success");
coefficients.push(shift);
}
}
//Legacy code.
// TODO: Remove
/*
let mut counter: u8 = 0;
let mut coefficients: Vec<u8> = vec![];
for blk in decoded {
let indices: Vec<u8> = poly::get_bit_indices_from_byte(blk);
for index in indices {
coefficients.push(counter*8+index);
}
counter += 1;
}
*/
coefficients
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn block2poly_task01() {
let block: &str = "ARIAAAAAAAAAAAAAAAAAgA==";
let coefficients: Vec<u8> = vec![0, 9, 12, 127];
assert_eq!(block2poly(block), coefficients);
}
}

View file

@ -4,7 +4,7 @@ use base64::prelude::*;
pub fn get_alpha_rep(num: u128) -> String {
let mut powers: Vec<u32> = vec![];
for shift in 0..127 {
for shift in 0..128 {
//println!("{:?}", ((num >> shift) & 1));
if (((num >> shift) & 1) == 1) {
println!("Shift success");
@ -29,7 +29,7 @@ pub fn get_alpha_rep(num: u128) -> String {
pub fn get_bit_indices_from_byte(byte: u8) -> Vec<u8> {
let mut coefficients: Vec<u8> = vec![];
for shift in 0..7 {
for shift in 0..8 {
if ((byte >> shift) & 1) == 1 {
coefficients.push(shift);
}