2018-11-27 22:28:37 +01:00
|
|
|
const P: [usize; 32] = [
|
|
|
|
16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19,
|
|
|
|
13, 30, 6, 22, 11, 4, 25,
|
|
|
|
];
|
|
|
|
|
|
|
|
fn p<T: Copy + Default>(i: [T; 32]) -> [T; 32] {
|
|
|
|
let mut res: [T; 32] = [T::default(); 32];
|
|
|
|
for (i, p) in i.iter().zip(P.iter()) {
|
|
|
|
res[*p - 1] = *i;
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let i: [u8; 32] = [
|
2018-11-28 17:07:14 +01:00
|
|
|
1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1,
|
|
|
|
0, 1,
|
2018-11-27 22:28:37 +01:00
|
|
|
];
|
|
|
|
p(i).iter().for_each(|i| print!("{}", i));
|
|
|
|
println!();
|
|
|
|
|
|
|
|
let p = &[
|
2018-11-28 17:07:14 +01:00
|
|
|
true, false, false, false, false, false, true, false, false, true, true, true, true, false,
|
|
|
|
false, true, true, true, false, true, false, true, true, true, true, false, true, true,
|
|
|
|
true, false, true, true,
|
2018-11-27 22:28:37 +01:00
|
|
|
];
|
|
|
|
let l0 = &[
|
|
|
|
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
|
|
|
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
|
|
|
|
true, true,
|
|
|
|
];
|
|
|
|
|
|
|
|
p.iter()
|
|
|
|
.zip(l0.iter())
|
|
|
|
.map(|(a, b)| a ^ b)
|
|
|
|
.map(|x| if x { '1' } else { '0' })
|
|
|
|
.for_each(|x| print!("{}", x));
|
|
|
|
println!();
|
2018-11-28 17:07:14 +01:00
|
|
|
|
|
|
|
let lo = b"11111111111111111111111111111101";
|
|
|
|
let ln = b"11111111111111111111111111111111";
|
|
|
|
let cl = lo.iter().zip(ln.iter()).filter(|(a, b)| a != b).count();
|
|
|
|
println!("cl = {}", cl);
|
|
|
|
|
|
|
|
let ro = b"01111101101001100010100011000100";
|
|
|
|
let rn = b"01111101100001100010100001000100";
|
|
|
|
let cr = ro.iter().zip(rn.iter()).filter(|(a, b)| a != b).count();
|
|
|
|
println!("cr = {}", cr);
|
2018-11-27 22:28:37 +01:00
|
|
|
}
|