bhcli

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

commit cf49c5895953fb212855254cf3dba3074fa85d71
parent c34582b1ecbb2e0c5a2771f3e4d307997ca87c37
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 30 Mar 2023 13:40:52 -0700

cleanup

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

diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs @@ -10,6 +10,9 @@ const _ALPHABET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST const ALPHABET1: &'static str = "abdcefgh1ijkImnpoqrstyQuvwxzABCDEGJKMNHLORPFSTlUVWXYZ023456789"; const LETTER_WIDTH: u32 = 8; const LETTER_HEIGHT: u32 = 14; +const NB_CHARS: u32 = 5; +const LEFT_PADDING: u32 = 5; // left padding for difficulty 1 and 2 +const TOP_PADDING: u32 = 7; // top padding for difficulty 1 and 2 lazy_static! { static ref B64_MAP: HashMap<&'static str, char> = HashMap::from([ @@ -107,9 +110,6 @@ pub fn solve_b64(b64_str: &str) -> Option<String> { } fn _solve_difficulty1(img: &DynamicImage) -> Option<String> { - const NB_CHARS: u32 = 5; - const LEFT_PADDING: u32 = 5; - const TOP_PADDING: u32 = 7; let mut answer = String::new(); for i in 0..NB_CHARS { let sub_img = img.crop_imm(LEFT_PADDING + ((LETTER_WIDTH+1)*i), TOP_PADDING, LETTER_WIDTH, LETTER_HEIGHT); @@ -133,9 +133,6 @@ fn _solve_difficulty1(img: &DynamicImage) -> Option<String> { // This function can solve both difficulty 1 and 2. fn solve_difficulty2(img: &DynamicImage) -> Option<String> { - const NB_CHARS: u32 = 5; - const LEFT_PADDING: u32 = 5; - const TOP_PADDING: u32 = 7; let mut answer = String::new(); for i in 0..NB_CHARS { let sub_img = img.crop_imm(LEFT_PADDING + ((LETTER_WIDTH +1)*i), TOP_PADDING, LETTER_WIDTH, LETTER_HEIGHT); @@ -167,7 +164,7 @@ impl Letter { fn center(&self) -> Point { let offset = self.offset(); - Point::new(offset.x + 4, offset.y + 6) + Point::new(offset.x + LETTER_WIDTH/2, offset.y + LETTER_HEIGHT/2) } } @@ -193,7 +190,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, CaptchaErr> { // Step1: Find all letters with red on the center let letters_map = find_letters(&img); - if letters_map.len() != 5 { + if letters_map.len() != NB_CHARS as usize { return Err(CaptchaErr(format!("did not find exactly 5 letters {}", letters_map.len()))); } @@ -206,7 +203,7 @@ fn solve_difficulty3(img: &DynamicImage) -> Result<String, CaptchaErr> { let mut letter = starting; answer.push(letter.character); visited.insert(letter.clone()); - for i in 0..4 { + for i in 0..NB_CHARS-1 { let top_left = Point::new(letter.offset.x-5, letter.offset.y-3); let mut rect = Rect{p1: top_left, width: LETTER_WIDTH+5+6, height: LETTER_HEIGHT+3+2}; let mut retry = 0; @@ -297,8 +294,8 @@ fn get_starting_letter(img: &DynamicImage, letters_map: &HashMap<char, Letter>) starting } -fn get_next_node(red_px_pts: &Vec<Point>, letter: &Letter, letters_map: &HashMap<char, Letter>, visited: &HashSet<Letter>, i: i32, nb_lines: usize) -> Option<Letter> { - if i == 3 { +fn get_next_node(red_px_pts: &Vec<Point>, letter: &Letter, letters_map: &HashMap<char, Letter>, visited: &HashSet<Letter>, i: u32, nb_lines: usize) -> Option<Letter> { + if i == NB_CHARS-2 { for (_, l) in letters_map.iter() { if !visited.contains(&l) { return Some(l.clone());