commit 3eda987d1a7167154b615a2933ca3062bc746d90
parent c761c279a0b62dfe2ac9deba9046e21302ab41ad
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 28 Mar 2023 20:34:37 -0700
auto solve captcha difficulty 1 and 2
Diffstat:
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/lechatphp/mod.rs b/src/lechatphp/mod.rs
@@ -1,11 +1,11 @@
use std::collections::HashMap;
use base64::{engine::general_purpose, Engine as _};
-use image::{ColorType, DynamicImage};
+use image::{ColorType, DynamicImage, GenericImageView, Rgba};
use lazy_static::lazy_static;
const B64_PREFIX: &'static str = "R0lGODlhCAAOAIAAAAAAAAAAACH5BAgAAAAALAAAAAAIAA4AgAQCBPz+/AI";
const _ALPHABET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-const _ALPHABET1: &'static str = "abdcefgh1ijkImnpoqrstyQuvwxzABCDEGJKMNHLORPFSTlUVWXYZ023456789";
+const ALPHABET1: &'static str = "abdcefgh1ijkImnpoqrstyQuvwxzABCDEGJKMNHLORPFSTlUVWXYZ023456789";
lazy_static! {
static ref B64_MAP: HashMap<&'static str, char> = HashMap::from([
@@ -74,13 +74,24 @@ lazy_static! {
]);
}
+fn get_letter_img(letter: char) -> Option<DynamicImage> {
+ for (k, v) in B64_MAP.iter() {
+ if *v == letter {
+ let img_dec = general_purpose::STANDARD.decode(format!("{}{}", B64_PREFIX, k)).unwrap();
+ let img = image::load_from_memory(&img_dec).ok()?;
+ return Some(img);
+ }
+ }
+ None
+}
+
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()?;
- solve_difficulty1(img)
+ solve_difficulty2(img)
}
-fn solve_difficulty1(img: DynamicImage) -> Option<String> {
+fn _solve_difficulty1(img: DynamicImage) -> Option<String> {
let mut answer = String::new();
for i in 0..5 {
let sub_img = img.crop_imm(5 + ((8+1)*i), 7, 8, 14);
@@ -100,4 +111,26 @@ fn solve_difficulty1(img: DynamicImage) -> Option<String> {
}
}
Some(answer)
+}
+
+fn solve_difficulty2(img: DynamicImage) -> Option<String> {
+ let on_color = Rgba::from([252, 254, 252, 255]);
+ let mut answer = String::new();
+ for i in 0..5 {
+ let sub_img = img.crop_imm(5 + ((8+1)*i), 7, 8, 14);
+ 'alphabet_loop: for c in ALPHABET1.chars() {
+ let good_letter_img = get_letter_img(c).unwrap();
+ for y in 0..14 {
+ for x in 0..8 {
+ if good_letter_img.get_pixel(x, y) == on_color &&
+ sub_img.get_pixel(x, y) != on_color {
+ continue 'alphabet_loop;
+ }
+ }
+ }
+ answer.push(c);
+ break;
+ }
+ }
+ Some(answer)
}
\ No newline at end of file