Exemplo n.º 1
0
        /// <summary>
        /// function for the masking of one string using either legacy parameters or normal ones
        /// </summary>
        /// <param name="s">string wich is going to be masked</param>
        /// <param name="parameters">parameter class containing all the options</param>
        /// <returns></returns>
        public string MaskString(string s, PassGenParameters parameters)
        {
            PassGenMaskOptions maskop;

            if (parameters.UseLegacyRules)
            {
                PassGenUtils.LegacyParser(parameters.LegacyRules, out maskop);
            }
            else
            {
                maskop                = new PassGenMaskOptions();
                maskop.CustomMasks    = new string[1];
                maskop.CustomMasks[0] = parameters.changeMask;
                for (int i = 0; i > parameters.additiveAmount; i++)
                {
                    maskop.Mask.Add(parameters.additiveMask);
                }
                foreach (char c in s.ToCharArray())
                {
                    maskop.Mask.Add(maskop.CustomMasks[0]); //TODO: not good
                }
                for (int i = 0; i > parameters.additiveAmount; i++)
                {
                    maskop.Mask.Add(parameters.additiveMask);
                }
            }
            ///Start Algorithm of Mask(input) Single time
            ulong a = MaskPossibility(maskop);

            return(MaskFromSeed((uint)new Random().Next(1, (int)a), maskop));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Overload of Generates string from "seed" and "maskopt".
 /// </summary>
 /// <param name="seed">the seed as input</param>
 /// <param name="maskopt">maskoptions for the masking</param>
 /// <param name="apos">output of possible amount of seeds</param>
 /// <returns>string wich contains the now masked word</returns>
 public string MaskFromSeed(uint seed, PassGenMaskOptions maskopt, out ulong apos)
 {
     apos = 1; //amount possible var
     foreach (string s in maskopt.Mask)
     {
         apos = apos * (uint)s.Length;
     }
     return(MaskFromSeed(seed, maskopt));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the amount of possiblities for this mask
        /// </summary>
        /// <param name="maskopt">Generator Mask</param>
        /// <returns>amount of possibilities</returns>
        public ulong MaskPossibility(PassGenMaskOptions maskopt)
        {
            ulong apos = 1;  //amount possible var

            foreach (string s in maskopt.Mask)
            {
                apos = apos * (uint)s.Length;
            }
            return(apos);
        }
Exemplo n.º 4
0
 public void SaveAllToFile(string filepath, PassGenMaskOptions maskopt, bool append = false)
 {
     using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filepath, append))
     {
         PassGenGenerator gen = new PassGenGenerator();
         ulong            a   = gen.MaskPossibility(maskopt);
         for (ulong i = 0; i < a; i++)
         {
             file.WriteLine(gen.MaskFromSeed(i, maskopt));
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Generates string from "seed" and "maskopt"
        /// </summary>
        /// <param name="seed">the seed as input</param>
        /// <param name="maskopt">mask options for the masking</param>
        /// <returns>string wich contains the now masked word</returns>
        public string MaskFromSeed(ulong seed, PassGenMaskOptions maskopt)
        {
            char[] newString = new char[maskopt.Mask.Count];
            ulong  next      = seed;

            for (int c = 0, i = maskopt.Mask.Count - 1; i > -1; i--, c++)
            {
                int   Length = maskopt.Mask.ToArray()[i].Length;
                ulong thiss  = next % (uint)Length;
                next         = next / (uint)Length;
                newString[i] = maskopt.Mask.ToArray()[i].ToCharArray()[thiss];
            }
            return(new string(newString));
        }
Exemplo n.º 6
0
        ///<summary>Generates an (PassGenMaskOptions) from lecagy parameters</summary>
        ///<param name="maskop">Outputs the (PassGenMaskOptions) for the parameters</param>
        /// <param name="parameters">Input of PassGenParameters where lecagy is enabled and legacy parameters are given</param>
        public static void LegacyParser(string legacyparameter, out PassGenMaskOptions maskop)
        {
            maskop = new PassGenMaskOptions();
            legacyparameter.Insert(legacyparameter.Length - 1, " ");
            char[] chars      = legacyparameter.ToCharArray();
            bool   Record     = false;
            char   lastchar   = ' ';
            byte   count      = 0;
            int    arraycount = 0;

            foreach (char ch in chars)
            {
                if (Record && lastchar != '}')
                {
                    maskop.Mask.Add(lastchar.ToString().ToLower() + lastchar.ToString().ToUpper());
                }
                else
                {
                    Record = false;  //if last character isn't the last in the string add the last to the masks in upper and lower case
                }
                if (count != 0)      //Else stop adding the last character
                {
                    int ab = 0;
                    if (int.TryParse(ch.ToString(), out ab))
                    {
                        // if it doesn't work(e.g. NaN), it won't addup and it goes to else
                        arraycount += ab * (int)Math.Pow(10, count - 1);
                    }
                    else
                    {
                        count = 0;
                        maskop.Mask.Add(maskop.CustomMasks[arraycount]);
                        lastchar = ch;
                        continue;
                    }
                    count++;
                }
                switch (lastchar)
                {
                case '?':
                    switch (ch)
                    {
                    case 'l':                                    //lowercase
                        maskop.Mask.Add(maskop.DefaultMasks[0]); //abcdefghijklmnopqrstuvwxyz
                        break;

                    case 'u':                                    //uppercase
                        maskop.Mask.Add(maskop.DefaultMasks[1]); //ABCDEFGHIJKLMNOPQRSTUVWXYZ
                        break;

                    case 'd':                                    //decimal
                        maskop.Mask.Add(maskop.DefaultMasks[2]); //1234567890
                        break;

                    case 'c':        //any Case
                        maskop.Mask.Add(maskop.DefaultMasks[0] + maskop.DefaultMasks[1]);
                        break;

                    case 't':        //Three most common masks
                        maskop.Mask.Add(maskop.DefaultMasks[0] + maskop.DefaultMasks[1] + maskop.DefaultMasks[2]);
                        break;

                    case 's':                                    //special
                        maskop.Mask.Add(maskop.DefaultMasks[3]); // !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~
                        break;

                    case 'a':                                                                                                               //all
                        maskop.Mask.Add(maskop.DefaultMasks[0] + maskop.DefaultMasks[1] + maskop.DefaultMasks[2] + maskop.DefaultMasks[3]); //abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~
                        break;
                    }
                    break;

                case '{':
                    Record = true;
                    break;

                case '}':
                    Record = false;
                    break;

                case '!':     //Custom mask use; counting 0 as valid
                    count = 1;
                    break;

                default:

                    break;
                }
                lastchar = ch;
            }
        }