Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return CrackResult instead of decoder names in path #105

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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