Skip to content

Commit 485f862

Browse files
committed
Merged training and production scripts into one
1 parent ffa7d69 commit 485f862

File tree

3 files changed

+104
-28
lines changed

3 files changed

+104
-28
lines changed

CAPTCHA Language Interpreter/Program.cs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,32 @@ static void Main(string[] args)
3131
Console.ReadKey();
3232
}
3333
}
34-
//// COMPILE
35-
//else if (args[0].ToUpper() == "-C")
36-
//{
37-
// if (File.Exists(args[1]))
38-
// {
39-
// string program = File.ReadAllText(args[1]);
40-
41-
// if (program.ToUpper().Contains("%IMAGE%"))
42-
// {
43-
// byte[] code = CompileScript(program);
44-
45-
46-
// }
47-
// else
48-
// {
49-
// Console.WriteLine("Compiled CAPTCHA Breaker scripts must contain a \"Solve, %IMAGE%\" command.");
50-
// Console.ReadKey();
51-
// }
52-
// }
53-
// else
54-
// {
55-
// Console.WriteLine("The file you specified does not exist!");
56-
// Console.ReadKey();
57-
// }
58-
//}
34+
}
35+
else if (args.Length == 3)
36+
{
37+
// SCRIPT RUN - Training Mode
38+
if (args[0].ToUpper() == "-S" && args[2].ToUpper() == "-T")
39+
{
40+
if (File.Exists(args[1]))
41+
{
42+
string program = File.ReadAllText(args[1]);
43+
Directory.SetCurrentDirectory(new FileInfo(args[1]).DirectoryName);
44+
CaptchaInterpreter run = new CaptchaInterpreter(program, true);
45+
run.Execute();
46+
}
47+
else
48+
{
49+
Console.WriteLine("The file you specified does not exist!");
50+
try
51+
{
52+
Console.Read();
53+
}
54+
catch
55+
{
56+
Console.ReadKey();
57+
}
58+
}
59+
}
5960
}
6061
else if (args.Length == 4)
6162
{
@@ -93,7 +94,17 @@ static void Main(string[] args)
9394
}
9495
else
9596
{
96-
Console.WriteLine("You must specify a captcha breaking script to run!");
97+
Console.WriteLine("CAPTCHA Breaking Scripting Language Interpreter");
98+
Console.WriteLine("https" + "://github.com/skotz/captcha-breaking-library");
99+
Console.WriteLine();
100+
Console.WriteLine("Usage:");
101+
Console.WriteLine(" Execute a script:");
102+
Console.WriteLine(" cbli.exe -s <scriptFile.captcha>");
103+
Console.WriteLine(" Execute a script in training mode:");
104+
Console.WriteLine(" cbli.exe -s <scriptFile.captcha> -t");
105+
Console.WriteLine(" Execute a script and pass an image to solve:");
106+
Console.WriteLine(" cbli.exe -s <scriptFile.captcha> -i <imageToSolve.bmp>");
107+
Console.WriteLine();
97108
Console.ReadKey();
98109
}
99110
}

SKOTDOC/Program.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Program
1010
{
1111
static void Main(string[] args)
1212
{
13-
Console.WriteLine("SKOTDOC v1.0 - Scott Clayton 2012");
13+
Console.WriteLine("SKOTDOC v1.0 - Scott Clayton 2012-2015");
1414
Console.WriteLine("For generating documentation in Wiki format for the CAPTCHA Breaking Language");
1515

1616
string verbatim = "";
@@ -73,6 +73,12 @@ static void Main(string[] args)
7373
current.Description += data + " ";
7474
}
7575
break;
76+
case "TRAINONLY":
77+
if (inBlock)
78+
{
79+
current.TrainingOnly = true;
80+
}
81+
break;
7682
case "BLOCKTYPE":
7783
if (inBlock)
7884
{
@@ -218,6 +224,10 @@ static void Main(string[] args)
218224
w.WriteLine("----");
219225
w.WriteLine("## {0}", f.Name);
220226
w.WriteLine("{0}", f.Description);
227+
if (f.TrainingOnly)
228+
{
229+
w.WriteLine("This method is only available when running in Training Mode.");
230+
}
221231

222232
int overload = 1;
223233
foreach (Overload o in f.Overloads)
@@ -324,6 +334,7 @@ class Function
324334
public List<Overload> Overloads { get; set; }
325335
public string Name { get; set; }
326336
public string Description { get; set; }
337+
public bool TrainingOnly { get; set; }
327338

328339
public Function()
329340
{

ScottClayton.Interpreter/CaptchaInterpreter.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class CaptchaInterpreter
3535

3636
private MODE mode = MODE.WARN;
3737

38+
private bool training;
39+
3840
//private string recreationData;
3941

4042
//private const string SPLITTER = ";~|!|~;";
@@ -53,13 +55,24 @@ public class CaptchaInterpreter
5355
private Dictionary<string, Bitmap> subtractionImages;
5456

5557
public CaptchaInterpreter(string program)
56-
: this(program, null)
58+
: this(program, null, false)
59+
{
60+
}
61+
62+
public CaptchaInterpreter(string program, bool trainingMode)
63+
: this(program, null, trainingMode)
5764
{
5865
}
5966

6067
public CaptchaInterpreter(string program, Bitmap image)
68+
: this(program, image, false)
69+
{
70+
}
71+
72+
public CaptchaInterpreter(string program, Bitmap image, bool trainingMode)
6173
{
6274
ProgramCode = program;
75+
training = trainingMode;
6376

6477
foreach (string term in CONST.LINE_TERMINATORS)
6578
{
@@ -92,6 +105,11 @@ void GlobalMessage_OnGlobalBitmapMessage(List<Bitmap> images, string tag)
92105
}
93106
}
94107

108+
public void Silence()
109+
{
110+
mode = MODE.QUIET;
111+
}
112+
95113
public string Execute()
96114
{
97115
string solution = "";
@@ -502,7 +520,13 @@ public string Execute()
502520
// #SKOTDOC.BLOCKSTART TESTSEGMENT
503521
// #SKOTDOC.BLOCKTYPE Working
504522
// #SKOTDOC.BLOCKDESC Test the preprocessing and segmentation setup on a test image and save the segmented parts to a folder.
523+
// #SKOTDOC.TRAINONLY
505524
case "TESTSEGMENT":
525+
if (!training)
526+
{
527+
break;
528+
}
529+
506530
string tsimage = args.GetQuotedArg(1);
507531
string tsfolder = args.GetQuotedArg(2);
508532

@@ -528,7 +552,13 @@ public string Execute()
528552
// #SKOTDOC.BLOCKSTART TRAIN
529553
// #SKOTDOC.BLOCKTYPE Working
530554
// #SKOTDOC.BLOCKDESC Train the solver on the patterns acquired or loaded.
555+
// #SKOTDOC.TRAINONLY
531556
case "TRAIN":
557+
if (!training)
558+
{
559+
break;
560+
}
561+
532562
string tfolder = args.GetQuotedArg(1);
533563
int titerations = args.GetArg(2).ToInt();
534564

@@ -565,7 +595,13 @@ public string Execute()
565595
// #SKOTDOC.BLOCKSTART TEST
566596
// #SKOTDOC.BLOCKTYPE Working
567597
// #SKOTDOC.BLOCKDESC Test the solver's ability to produce correct predictions on the patterns acquired or loaded. (Use patterns that were not used in training or you will get skewed results.)
598+
// #SKOTDOC.TRAINONLY
568599
case "TEST":
600+
if (!training)
601+
{
602+
break;
603+
}
604+
569605
string testfolder = args.GetQuotedArg(1);
570606

571607
switch (args.Count - 1)
@@ -590,7 +626,13 @@ public string Execute()
590626
// #SKOTDOC.BLOCKSTART FULLTEST
591627
// #SKOTDOC.BLOCKTYPE Working
592628
// #SKOTDOC.BLOCKDESC Perform a full test (completely solving a CAPTCHA) and give the actual percentage of CAPTCHAs that were completely and correctly solved.
629+
// #SKOTDOC.TRAINONLY
593630
case "FULLTEST":
631+
if (!training)
632+
{
633+
break;
634+
}
635+
594636
string fullfolder = args.GetQuotedArg(1);
595637
string fullreport = args.GetQuotedArg(2);
596638
string fullext = args.GetQuotedArg(3);
@@ -672,7 +714,13 @@ public string Execute()
672714
// #SKOTDOC.BLOCKSTART SAVE
673715
// #SKOTDOC.BLOCKTYPE Working
674716
// #SKOTDOC.BLOCKDESC Save the DataBase of trained patterns to a file so that it can be loaded later. The idea is to distribute the database file with your finished script (the finished script shouldn't do any training, only efficient solving).
717+
// #SKOTDOC.TRAINONLY
675718
case "SAVE":
719+
if (!training)
720+
{
721+
break;
722+
}
723+
676724
string saveLoc = args.GetQuotedArg(1);
677725

678726
switch (args.Count - 1)
@@ -705,6 +753,12 @@ public string Execute()
705753
// #SKOTDOC.BLOCKTYPE Working
706754
// #SKOTDOC.BLOCKDESC Load a pattern database. The database you load needs to have been saved under the same setup conditions as the script is being loaded under.
707755
case "LOAD":
756+
// Only when not training
757+
if (training)
758+
{
759+
break;
760+
}
761+
708762
string dbLoc = args.GetQuotedArg(1);
709763
string base64 = args.GetQuotedArg(2);
710764

0 commit comments

Comments
 (0)