Skip to content

Commit

Permalink
Merge pull request #105 from bee-san/crackres
Browse files Browse the repository at this point in the history
return CrackResult instead of decoder names in path
  • Loading branch information
SkeletalDemise authored Nov 26, 2022
2 parents db297dc + 39e83c1 commit 1bcc994
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/decoders/crack_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::interface::Decoder;
/// Every cracker returns this object which
/// Either indicates success or failure among other things.
#[derive(Debug, Clone)]
pub struct CrackResult {
/// If our checkers return success, we change this bool to True
pub success: bool,
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ mod storage;
mod timer;

use crate::config::Config;

use self::decoders::crack_results::CrackResult;
/// The main function to call which performs the cracking.
/// ```rust
/// use ares::perform_cracking;
Expand All @@ -58,7 +60,7 @@ pub struct Text {
/// text we got
pub text: String,
/// decoder used so far to get this text
pub path: Vec<&'static str>,
pub path: Vec<CrackResult>,
}

#[cfg(test)]
Expand Down
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ fn main() {
let (text, config) = parse_cli_args();
let result = perform_cracking(&text, config);
match result {
// TODO: As result have array of CrackResult used,
// we can print in better way with more info
Some(result) => {
println!("SUCCESSFUL 😁");
println!("PLAINTEXT: {:?}", result.text);
println!("DECODERS USED: {}", result.path.join(" → "))
println!(
"DECODERS USED: {}",
result
.path
.iter()
.map(|c| c.decoder)
.collect::<Vec<_>>()
.join(" → ")
)
}
None => println!("FAILED 😭"),
}
Expand Down
10 changes: 6 additions & 4 deletions src/searchers/bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ pub fn bfs(input: &str) -> Option<Text> {
// so just stop processing further.
MyResults::Break(res) => {
let mut decoders_used = current_string.path;
decoders_used.push(res.decoder);
let text = res.unencrypted_text.clone().unwrap_or_default();
decoders_used.push(res);
let result_text = Text {
text: res.unencrypted_text.unwrap_or_default(),
text,
path: decoders_used,
};

Expand All @@ -54,9 +55,10 @@ pub fn bfs(input: &str) -> Option<Text> {
.into_iter()
.map(|r| {
let mut decoders_used = current_string.path.clone();
decoders_used.push(r.decoder);
let text = r.unencrypted_text.clone().unwrap_or_default();
decoders_used.push(r);
Text {
text: r.unencrypted_text.unwrap_or_default(),
text,
path: decoders_used,
}
})
Expand Down

0 comments on commit 1bcc994

Please sign in to comment.