bhcli

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

commit 81ec0205348f6f9aa0d103c31a97d23f29d8d886
parent 3c4b4e6ffc9fae8bf1d3e0cfd2ec234eda69713f
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 29 Mar 2023 23:07:26 -0700

simplify code

Diffstat:
Msrc/lechatphp/mod.rs | 29+++++++----------------------
1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs @@ -282,47 +282,32 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, CaptchaErr> { let mut rect = Rect{p1: top_left, width: 8+5+6, height: 14+3+2}; let mut retry = 0; - 'the_loop: loop { + 'retry_loop: loop { retry += 1; let square = img.crop_imm(rect.p1.x, rect.p1.y, rect.width, rect.height); let red_px_pts = get_contour_red_pixels(&rect.p1, &square); if i == 0 { - if red_px_pts.len() == 0 { + if red_px_pts.len() != 1 { if retry < 10 { rect.enlarge(); continue; } - return Err(CaptchaErr(format!("root {:?} has no line detected", letter))); - } - if red_px_pts.len() > 1 { - return Err(CaptchaErr(format!("root {:?} has more than one line detected", letter))); + return Err(CaptchaErr(format!("root {:?} does not have exactly 1 line detected", letter))); } let red_pt = red_px_pts.get(0).unwrap(); let angle = get_angle(red_pt, &letter.center()); let neighbor = get_letter_in_direction(&letter, angle, &letters_map).unwrap(); letter = neighbor.clone(); - break; - } - - if red_px_pts.len() == 0 { - if retry < 10 { - rect.enlarge(); - continue; - } - return Err(CaptchaErr(format!("letter #{} {:?} has no line detected", i+1, letter))); + break 'retry_loop; } - if red_px_pts.len() == 1 { + if red_px_pts.len() != 2 { if retry < 10 { rect.enlarge(); continue; } - return Err(CaptchaErr(format!("letter #{} {:?} has only 1 line detected", i+1, letter))); - } - - if red_px_pts.len() > 2 { - return Err(CaptchaErr(format!("letter #{} {:?} has more than 2 lines detected", i+1, letter))); + return Err(CaptchaErr(format!("letter #{} {:?} doesn't have exactly 2 lines detected", i+1, letter))); } let fst_red_pt = red_px_pts.get(0).unwrap(); @@ -338,7 +323,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, CaptchaErr> { for (_, l) in letters_map.iter() { if !visited.contains(&l) { letter = l.clone(); - break 'the_loop; + break 'retry_loop; } } }