Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Solves Captcha on the NZ Government's "Hand in firearms" form https://forms.police.govt.nz/forms/firearms-hand-in
- //Probably can be adapted to break captchas for other shitty Math Based captchas.
- using NCalc;
- using System;
- using System.Collections.Generic;
- using Flurl.Http;
- using HtmlAgilityPack;
- namespace CaptchaBreaker
- {
- class Program
- {
- static Dictionary<String, String> NumberStrings = new Dictionary<String, String>
- {
- { "zero", "0" },
- { "one", "1" },
- { "two", "2" },
- { "three", "3" },
- { "four", "4" },
- { "five", "5" },
- { "six", "6" },
- { "seven", "7" },
- { "eight", "8" },
- { "nine", "9" },
- { "ten", "10" },
- { "eleven", "11" },
- { "twelve", "12" },
- { "thirteen", "13" },
- { "fourteen", "14" },
- { "fifteen", "15" },
- { "plus", "+" },
- { "minus", "-" },
- { "times", "*" },
- { "equals", "=" },
- { "devide", "/" }
- };
- static string FindNeededValue(String Equation)
- {
- string[] Components = Equation.Split(' ');
- int i = 0;
- foreach (String Component in Components)
- {
- if (Component == "=")
- {
- return Components[i + 1];
- }
- i++;
- }
- return "0";
- }
- static int FindX(String Equation)
- {
- int i = 0;
- int NeededValue = int.Parse(FindNeededValue(Equation));
- String FinalEquation = Equation.Substring(0, Equation.IndexOf('='));
- while (true)
- {
- string Try = FinalEquation.Replace("X", i.ToString());
- Expression e = new Expression(Try);
- if ((int)e.Evaluate() == NeededValue)
- {
- return i;
- }
- i++;
- }
- }
- static int SolveEquation(string Equation)
- {
- String[] Components = Equation.Split(' ');
- List<String> Reconstructed = new List<String>();
- foreach(String Component in Components)
- {
- try
- {
- int.Parse(Component);
- Reconstructed.Add(Component);
- }
- catch(Exception)
- {
- if (Component == "X")
- {
- Reconstructed.Add("X");
- }
- if (NumberStrings.ContainsKey(Component))
- {
- Reconstructed.Add(NumberStrings[Component]);
- }
- }
- }
- String FinalEquation = String.Join(" ", Reconstructed.ToArray());
- if(FinalEquation.Contains("X"))
- {
- return FindX(FinalEquation);
- }
- try
- {
- FinalEquation = FinalEquation.Substring(0, FinalEquation.IndexOf('='));
- }
- catch (Exception) { };
- Expression e = new Expression(FinalEquation);
- return (int)e.Evaluate();
- }
- static void Main(string[] args)
- {
- while(true)
- {
- var Request = "https://forms.police.govt.nz/forms/firearms-hand-in".GetStringAsync();
- Request.Wait();
- String PageHtml = Request.Result;
- var doc = new HtmlDocument();
- doc.LoadHtml(PageHtml);
- var Node = doc.DocumentNode.SelectSingleNode("//*[@id=\"webform-client-form-155\"]/div/fieldset/div/div[2]/span[1]");
- var Node2 = doc.DocumentNode.SelectSingleNode("//*[@id=\"webform-client-form-155\"]/div/fieldset/div/div[2]/span[2]");
- String FullEquation;
- String Eq1 = Node.InnerText;
- String Eq2 = "";
- if (Node2 != null)
- {
- Eq2 = Node2.InnerText;
- FullEquation = Eq1 + "X" + Eq2;
- }
- else if (Eq1.StartsWith(" "))
- {
- FullEquation = "X" + Eq1;
- }
- else
- {
- FullEquation = Eq1;
- }
- Console.WriteLine(FullEquation);
- Console.WriteLine(SolveEquation(FullEquation));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement