replaced transpose with naive implementation for now

This commit is contained in:
sinuio
2022-02-18 14:24:00 -08:00
parent 855e2dfcb3
commit 41e4d447e6
2 changed files with 34 additions and 13 deletions

View File

@@ -250,7 +250,7 @@ mod tests {
rng.fill_bytes(&mut choice);
let choice = u8vec_to_boolvec(&choice);
let inputs: Vec<[Block; 2]> = (0..16)
.map(|i| [Block::from(2 * i), Block::from(2 * i + 1)])
.map(|i| [Block::random(&mut rng), Block::random(&mut rng)])
.collect();
let receiver_setup = receiver.extension_setup(&choice);

View File

@@ -20,27 +20,48 @@ pub fn u8vec_to_boolvec(v: &[u8]) -> Vec<bool> {
}
pub fn transpose(m: &Vec<Vec<u8>>) -> Vec<Vec<u8>> {
let col_count = m[0].len() * 8;
let row_count = m.len();
let bits: Vec<Vec<bool>> = m.iter().map(|row| u8vec_to_boolvec(row)).collect();
let col_count = bits[0].len();
let row_count = bits.len();
let mut bits_: Vec<Vec<bool>> = vec![vec![false; row_count]; col_count];
let mut m_: Vec<Vec<u8>> = Vec::with_capacity(col_count);
for j in 0..col_count {
let byte_n = j >> 3;
let bit_idx = j % 8;
for j in 0..row_count {
for i in 0..col_count {
bits_[i][j] = bits[j][i];
}
}
let mut row_bits: Vec<bool> = (0..row_count)
.map(|i| ((m[i][byte_n] >> (7 - bit_idx)) & 1) == 1)
.collect();
row_bits.reverse();
let mut row = boolvec_to_u8vec(&row_bits);
row.reverse();
m_.push(row);
for row in bits_.iter() {
m_.push(boolvec_to_u8vec(row));
}
m_
}
// pub fn transpose(m: &Vec<Vec<u8>>) -> Vec<Vec<u8>> {
// let col_count = m[0].len() * 8;
// let row_count = m.len();
// let mut m_: Vec<Vec<u8>> = Vec::with_capacity(col_count);
// for j in 0..col_count {
// let byte_n = j >> 3;
// let bit_idx = j % 8;
// let mut row_bits: Vec<bool> = (0..row_count)
// .map(|i| ((m[i][byte_n] >> (7 - bit_idx)) & 1) == 1)
// .collect();
// row_bits.reverse();
// let mut row = boolvec_to_u8vec(&row_bits);
// row.reverse();
// m_.push(row);
// }
// m_
// }
#[cfg(test)]
mod tests {
use super::*;