Skip to content

Commit

Permalink
Manual chunk size option. Fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpclark committed Dec 7, 2017
1 parent 43f04fb commit baa7de3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ sudo cp target/release/abrute /usr/bin/
in the attempts.
-s, --start Starting character sequence to begin with.
-z, --zip Use `unzip` decryption instead of `aescrypt`.
-c, --chunk Workload chunk size per core before status update.
Defaults to 32.
<TARGET> Target file to decrypt. The target must be preceeded
by a double dash: -- target.aes
-h, --help Prints help information.
Expand Down
20 changes: 14 additions & 6 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn has_five_minutes_passed(t: Instant) -> bool {
Instant::now().duration_since(t) > Duration::new(300,0)
}

fn chunk_sequence(d: &mut Digits, adj: Option<String>) -> Vec<String> {
let qty: usize = num_cpus::get() * 32;
fn chunk_sequence(d: &mut Digits, adj: Option<String>, chunk: usize) -> Vec<String> {
let qty: usize = num_cpus::get() * chunk;
let mut counter = 0;
let mut result = vec![];
loop {
Expand Down Expand Up @@ -81,13 +81,17 @@ fn has_reached_end<'a>(sequencer: &Digits, max: usize) -> Result<(), Error> {
}

pub fn aescrypt_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let WorkLoad(characters, max, mut sequencer, target, adj) = work_load;
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size) = work_load;
let mut time_keeper = Instant::now();
loop {
has_reached_end(&sequencer, max)?;
progress_report(&sequencer);

let chunk = chunk_sequence(&mut sequencer, adj.clone());
let chunk = chunk_sequence(
&mut sequencer,
adj.clone(),
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap())
);
let code: Mutex<Vec<String>> = Mutex::new(vec![]);

chunk.par_iter().for_each(|ref value|
Expand Down Expand Up @@ -149,7 +153,7 @@ fn any_file_contents(dir: &TempDir, omit: &str) -> bool {
}

pub fn unzip_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let WorkLoad(characters, max, mut sequencer, target, adj) = work_load;
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size) = work_load;
let mut time_keeper = Instant::now();
if let Ok(dir) = TempDir::new("abrute") {
let cwd = env::current_dir().unwrap();
Expand All @@ -162,7 +166,11 @@ pub fn unzip_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
has_reached_end(&sequencer, max)?;
progress_report(&sequencer);

let chunk = chunk_sequence(&mut sequencer, adj.clone());
let chunk = chunk_sequence(
&mut sequencer,
adj.clone(),
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap())
);
let code: Mutex<Vec<Result<(), Error>>> = Mutex::new(vec![]);

chunk.par_iter().for_each(|ref value|
Expand Down
26 changes: 20 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ extern crate clap;
use clap::{Arg, App};

pub struct WorkLoad(
pub String, // characters: String,
pub usize, // max: usize,
pub Digits, // mut sequencer: Digits,
pub String, // target: &str,
pub Option<String> // adj: Option<&str>
pub String, // characters: String,
pub usize, // max: usize,
pub Digits, // mut sequencer: Digits,
pub String, // target: String,
pub Option<String>, // adj: Option<String>
pub Option<String> // chunk: Option<String>
);

fn run_app() -> Result<(), Error> {
Expand Down Expand Up @@ -61,6 +62,11 @@ fn run_app() -> Result<(), Error> {
long("zip").
takes_value(false)
).
arg(Arg::with_name("chunk").
short("c").
long("chunk").
takes_value(true)
).
arg(Arg::with_name("TARGET").
required(true).
last(true)
Expand All @@ -83,6 +89,8 @@ fn run_app() -> Result<(), Error> {
in the attempts.
-s, --start Starting character sequence to begin with.
-z, --zip Use `unzip` decryption instead of `aescrypt`.
-c, --chunk Workload chunk size per core before status update.
Defaults to 32.
<TARGET> Target file to decrypt. The target must be preceeded
by a double dash: -- target.aes
-h, --help Prints help information.
Expand Down Expand Up @@ -113,6 +121,11 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
validate_and_prep_sequencer_adjacent(&mut sequencer, adjacent)?;
validate_file_exists(&target)?;

let chunk = matches.value_of("chunk");
if matches.is_present("chunk") {
validate_chunk_input(&chunk.unwrap()[..])?;
}

// Begin Resume Feature
let starting = sequencer.to_s();
use ::resume::{ResumeKey,ResumeFile};
Expand All @@ -134,7 +147,8 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
max,
sequencer,
target.to_string(),
adjacent.map(str::to_string)
adjacent.map(str::to_string),
chunk.map(str::to_string)
);

if matches.is_present("zip") {
Expand Down
8 changes: 8 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum Error {
FileMissing,
InvalidAdjacentNumber,
InvalidCharacterSet,
InvalidChunkNumber,
InvalidRange,
InvalidStringLength,
PasswordNotFound,
Expand All @@ -30,6 +31,7 @@ impl fmt::Display for Error {
Error::FileMissing => f.write_str("FileMissing" ),
Error::InvalidAdjacentNumber => f.write_str("InvalidAdjacentNumber"),
Error::InvalidCharacterSet => f.write_str("InvalidCharacterSet" ),
Error::InvalidChunkNumber => f.write_str("InvalidChunkNumber"),
Error::InvalidRange => f.write_str("InvalidRange" ),
Error::InvalidStringLength => f.write_str("InvalidStringLength" ),
Error::PasswordNotFound => f.write_str("PasswordNotFound" ),
Expand Down Expand Up @@ -64,6 +66,11 @@ fn invalid_character_set() -> &'static str {
"Invalid character set provided for start."
}

#[inline]
fn invalid_chunk_number() -> &'static str {
"Invalid number for chunk input."
}

#[inline]
fn invalid_range() -> &'static str {
"Invalid range input given."
Expand Down Expand Up @@ -97,6 +104,7 @@ impl StdError for Error {
Error::FileMissing => file_missing(),
Error::InvalidAdjacentNumber => invalid_adjacent_number(),
Error::InvalidCharacterSet => invalid_character_set(),
Error::InvalidChunkNumber => invalid_chunk_number(),
Error::InvalidRange => invalid_range(),
Error::InvalidStringLength => invalid_string_length(),
Error::PasswordNotFound => password_not_found(),
Expand Down
5 changes: 5 additions & 0 deletions src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub fn validate_adjacent_input(v: String) -> Result<(), Error> {
Err(Error::InvalidAdjacentNumber)
}

pub fn validate_chunk_input(v: &str) -> Result<(), Error> {
if v.parse::<usize>().is_ok() { return Ok(()); }
Err(Error::InvalidChunkNumber)
}

pub fn validate_start_string(matches: &clap::ArgMatches, max: usize) -> Result<(), Error> {
if let Some(s) = matches.value_of("start") {
if s.len() > max { return Err(Error::InvalidStringLength); }
Expand Down

0 comments on commit baa7de3

Please sign in to comment.