Poly2Block; Block2Poly; SEA128 tasks working #2
3 changed files with 66 additions and 5 deletions
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal 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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,52 @@
|
||||||
|
use std::str::Bytes;
|
||||||
|
|
||||||
use crate::utils::poly;
|
use crate::utils::poly;
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
|
|
||||||
fn block2poly(block: String) {
|
fn block2poly(block: &str) -> Vec<u8> {
|
||||||
let num_block: u128 = BASE64_STANDARD.decode(block).unwrap().into();
|
// Convert JSON data in to a u128
|
||||||
let coefficients = poly::get_bit_indices_from_byte();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ use base64::prelude::*;
|
||||||
pub fn get_alpha_rep(num: u128) -> String {
|
pub fn get_alpha_rep(num: u128) -> String {
|
||||||
let mut powers: Vec<u32> = vec![];
|
let mut powers: Vec<u32> = vec![];
|
||||||
|
|
||||||
for shift in 0..127 {
|
for shift in 0..128 {
|
||||||
//println!("{:?}", ((num >> shift) & 1));
|
//println!("{:?}", ((num >> shift) & 1));
|
||||||
if (((num >> shift) & 1) == 1) {
|
if (((num >> shift) & 1) == 1) {
|
||||||
println!("Shift success");
|
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> {
|
pub fn get_bit_indices_from_byte(byte: u8) -> Vec<u8> {
|
||||||
let mut coefficients: Vec<u8> = vec![];
|
let mut coefficients: Vec<u8> = vec![];
|
||||||
|
|
||||||
for shift in 0..7 {
|
for shift in 0..8 {
|
||||||
if ((byte >> shift) & 1) == 1 {
|
if ((byte >> shift) & 1) == 1 {
|
||||||
coefficients.push(shift);
|
coefficients.push(shift);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue