/// <summary> /// generate random text for the CAPTCHA /// </summary> /// <returns></returns> private string GenerateRandomText() { StringBuilder sb = new StringBuilder(TextLength); int maxLength = TextChars.Length; for (int n = 0; n <= TextLength - 1; n++) { sb.Append(TextChars.Substring(_rand.Next(maxLength), 1)); } return(sb.ToString()); }
private string GenerateRandomText() { var builder = new StringBuilder(); int length = TextChars.Length; for (int i = 0; i < TextLength; i++) { builder.Append(TextChars.Substring(Random.Next(length), 1)); } DateGenerated = DateTime.UtcNow; return(builder.ToString()); }
public SolverSyntaxCore() { TextChars.Add('_'); BreakChars.Add('('); BreakChars.Add(')'); BreakChars.Add('.'); BreakChars.Add(','); Keywords.Add(new Keyword(KeywordType.LeftBracket, "(")); Keywords.Add(new Keyword(KeywordType.RightBracket, ")")); Keywords.Add(new Keyword(KeywordType.EndLine, ";")); Keywords.Add(new Keyword(KeywordType.Comma, ",")); Keywords.Add(new Operator(KeywordType.Binary, "*", Mul)); Keywords.Add(new Operator(KeywordType.Binary, "+", Add)); }
//static void Plus(Runtime r) //{ // var b = r.stack.Pop(); // var a = r.stack.Pop(); // r.stack.Push((int.Parse(b) + int.Parse(a)).ToString()); //} //static void Print(Runtime r) //{ // Console.WriteLine(r.stack.Pop()); //} //static Stack<int> elseStack = new Stack<int>(); //static void Else(Runtime r) //{ // int k = r.args.Pop(); // //elseStack.Push(k); // //var b = r.stack.Pop(); // //var a = r.stack.Pop(); // //r.stack.Push((int.Parse(b) + int.Parse(a)).ToString()); //} //static void Elif(Runtime r) //{ // int k = r.args.Pop(); // //elseStack.Push(k); // //var b = r.stack.Pop(); // //var a = r.stack.Pop(); // //r.stack.Push((int.Parse(b) + int.Parse(a)).ToString()); //} //static void If(Runtime r) //{ // int k = r.args.Pop(); // //elseStack.Push(k); // //var b = r.stack.Pop(); // //var a = r.stack.Pop(); // //r.stack.Push((int.Parse(b) + int.Parse(a)).ToString()); //} public DefaultSyntaxCore() { TextChars.Add('_'); BreakChars.Add('('); BreakChars.Add(')'); BreakChars.Add('.'); BreakChars.Add(','); //Keywords.Add(new Operator(KeywordType.Binary, "+", Plus)); //Keywords.Add(new Operator(KeywordType.Prefix, "+", Plus)); //Keywords.Add(new Operator(KeywordType.Postfix, "+", Plus)); //Keywords.Add(new Operator(KeywordType.Postfix, "++", Plus)); //Keywords.Add(new Operator(KeywordType.Prefix, "print", Print, -100)); //Keywords.Add(new NestedOperator(KeywordType.Prefix, "if", If, 0, -500)); ////Keywords.Add(new Operator(KeywordType.Prefix, "iff", If, -500)); //Keywords.Add(new NestedOperator(KeywordType.Prefix, "else", Else, 0, -500)); //Keywords.Add(new NestedOperator(KeywordType.Prefix, "elif", Elif, 0, -500)); //Keywords.Add(new Operator(KeywordType.Prefix, "?", Print, -500)); //Keywords.Add(new Operator(KeywordType.Prefix, ":", Print, -600)); Keywords.Add(new Keyword(KeywordType.LeftBracket, "(")); Keywords.Add(new Keyword(KeywordType.RightBracket, ")")); Keywords.Add(new Keyword(KeywordType.EndLine, ";")); Keywords.Add(new Keyword(KeywordType.Comma, ",")); }