Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- public class BruteforceGenerator{
- public char[] CharSet{ get; private set; }
- public int Length{ get; private set; }
- public short[] State{ get; private set; }
- public string Current{ get; private set; }
- public BruteforceGenerator(char[] CharSet, int Length, short[] State){
- this.CharSet = CharSet;
- this.Length = Length;
- this.State = State;
- this.Current = "";
- }
- public BruteforceGenerator(char[] CharSet, int Length){
- this.CharSet = CharSet;
- this.Length = Length;
- this.State = new short[Length];
- this.State[Length - 1] = -1;
- this.Current = "";
- }
- public string Next(){
- if(Current == null) return null;
- this.State[Length - 1]++;
- for(int i = Length - 1; i >= 0; i--){
- if(State[i] == CharSet.Length){
- State[i] = 0;
- if(i > 0) State[i - 1]++;
- else{
- Current = null;
- return null;
- }
- }
- }
- Current = "";
- for(int i = 0; i < Length; i++)
- Current += CharSet[State[i]];
- return Current;
- }
- }
- public class WordlistProcessor{
- public string Filename{ get; private set; }
- private TextReader WordlistReader;
- public string Current{ get; private set; }
- private Stack<string> Mutations;
- public WordlistProcessor(string Filename){
- this.Current = "";
- this.Mutations = new Stack<string>();
- this.Filename = Filename;
- this.WordlistReader = new StreamReader(new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read));
- }
- private void ReadNext(){
- String Line = WordlistReader.ReadLine();
- Mutations.Clear();
- if(Line == null) return;
- string Mutation;
- for(int i = 0; i < Math.Pow(2, Line.Length); i++){
- Mutation = "";
- for(int j = 0; j < Line.Length; j++){
- char c = Line[j];
- if((i & (1 << j)) != 0) Mutation += (c >= 'a' && c <= 'z') ? (char)(c ^ 32) : c;
- else Mutation += (c >= 'A' && c <= 'Z') ? (char)(c ^ 32) : c;
- }
- Mutations.Push(Mutation);
- }
- }
- public string Next(){
- if(Current == null) return null;
- if(Mutations.Count > 0){
- Current = Mutations.Pop();
- }
- else{
- ReadNext();
- if(Mutations.Count <= 0) Current = null;
- else Current = Mutations.Pop();
- }
- return Current;
- }
- public void Close(){
- WordlistReader.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement