Parallelize calculate models
This commit is contained in:
parent
0dedbd16a3
commit
fc9133056c
1 changed files with 7 additions and 6 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -6,7 +6,9 @@ use aes::{
|
||||||
cipher::{BlockEncrypt, KeyInit, generic_array::GenericArray},
|
cipher::{BlockEncrypt, KeyInit, generic_array::GenericArray},
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{
|
||||||
|
IndexedParallelIterator, IntoParallelIterator, IntoParallelRefMutIterator, ParallelIterator,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
io::{BufRead, Read},
|
io::{BufRead, Read},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
|
@ -75,14 +77,13 @@ fn calculate_models(ciphertexts: &[[u8; 16]]) -> Vec<[Vec<u8>; 16]> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
r.par_iter_mut().enumerate().for_each(|(j, r)| {
|
||||||
for k in 0..16 {
|
for k in 0..16 {
|
||||||
for j in 0..256 {
|
|
||||||
for (i, c) in ciphertexts.iter().enumerate() {
|
for (i, c) in ciphertexts.iter().enumerate() {
|
||||||
r[j][k][i] = RSBOX[(c[k] ^ (j as u8)) as usize];
|
r[k][i] = RSBOX[(c[k] ^ (j as u8)) as usize];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue