bhcli

"Strange's fork of n0tr1v's bhcli (onion)"
git clone https://git.dasho.dev/Strange/bhcli.git
Log | Files | Refs | README

commit 12d12dfee383a8d1b7f7284a836a6e8fbd9ac940
parent 641c7ebec87a5db0749afce0f6203c58dca4326a
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 29 Mar 2023 17:52:25 -0700

cleanup

Diffstat:
Msrc/lechatphp/mod.rs | 31++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs @@ -89,7 +89,13 @@ pub fn solve_b64(b64_str: &str) -> Option<String> { let img_dec = general_purpose::STANDARD.decode(b64_str.strip_prefix("data:image/gif;base64,")?).ok()?; let img = image::load_from_memory(&img_dec).ok()?; if img.dimensions().0 > 60 { - return solve_difficulty3(&img).ok(); + match solve_difficulty3(&img) { + Ok(answer) => return Some(answer), + Err(_e) => { + // println!("{:?}", e); + return None; + }, + } } solve_difficulty2(&img) } @@ -159,12 +165,15 @@ impl Letter { } } +#[derive(Debug)] +struct CaptchaErr(String); + // SolveDifficulty3 solve captcha for difficulty 3 // For each pixel, verify if a match is found. If we do have a match, // verify that we have some "red" in it. // // Red circle is 17x17 (initial point) -fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { +fn solve_difficulty3(img: &DynamicImage) -> Result<String, CaptchaErr> { //img.save(format!("captcha.gif")).unwrap(); let image_width = 150; let image_height = 200; @@ -218,7 +227,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { } if letters_map.len() != 5 { - return Err(format!("did not find exactly 5 letters {}", letters_map.len())); + return Err(CaptchaErr(format!("did not find exactly 5 letters {}", letters_map.len()))); } let mut starting: Option<Letter> = None; @@ -233,7 +242,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { } if starting.is_none() { - return Err("could not find starting letter".to_owned()); + return Err(CaptchaErr("could not find starting letter".to_owned())); } let mut answer = String::new(); @@ -241,7 +250,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { let mut visited = HashSet::<String>::new(); for i in 0..5 { if visited.contains(&letter.key()) { - return Err(format!("already visited node {:?}", letter)); + return Err(CaptchaErr(format!("already visited node {:?}", letter))); } answer.push(letter.character); // println!("visiting {:?}", letter); @@ -265,10 +274,10 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { rect.enlarge(); continue; } - return Err(format!("root {:?} has no line detected", letter)); + return Err(CaptchaErr(format!("root {:?} has no line detected", letter))); } if red_px_pts.len() > 1 { - return Err(format!("root {:?} has more than one line detected", letter)); + return Err(CaptchaErr(format!("root {:?} has more than one line detected", letter))); } let red_pt = red_px_pts.get(0).unwrap(); let angle = get_angle(red_pt, &letter.center()); @@ -282,7 +291,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { rect.enlarge(); continue; } - return Err(format!("letter #{} {:?} has no line detected", i+1, letter)); + return Err(CaptchaErr(format!("letter #{} {:?} has no line detected", i+1, letter))); } if red_px_pts.len() == 1 { @@ -290,11 +299,11 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { rect.enlarge(); continue; } - return Err(format!("letter #{} {:?} has only 1 line detected", i+1, letter)); + return Err(CaptchaErr(format!("letter #{} {:?} has only 1 line detected", i+1, letter))); } if red_px_pts.len() > 2 { - return Err(format!("letter #{} {:?} has more than 2 lines detected", i+1, letter)); + return Err(CaptchaErr(format!("letter #{} {:?} has more than 2 lines detected", i+1, letter))); } let fst_red_pt = red_px_pts.get(0).unwrap(); @@ -314,7 +323,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, String> { } } } - return Err(format!("letter #{} {:?} all neighbors already visited", i+1, letter)); + return Err(CaptchaErr(format!("letter #{} {:?} all neighbors already visited", i+1, letter))); } } letter = neighbor;