40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
|
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] = [
|
||
|
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, 0,
|
||
|
0, 0,
|
||
|
];
|
||
|
p(i).iter().for_each(|i| print!("{}", i));
|
||
|
println!();
|
||
|
|
||
|
let p = &[
|
||
|
true, false, false, false, false, false, true, false, false, true, false, true, true,
|
||
|
false, false, true, true, true, false, true, false, true, true, true, false, false, true,
|
||
|
true, true, false, true, true,
|
||
|
];
|
||
|
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!();
|
||
|
}
|