Exemplo n.º 1
0
 private void doRounds(BitArray[] data, BitArray[] Keys, EncType mode)
 {
     BitArray[] L = new BitArray[NumRounds + 1];
     BitArray[] R = new BitArray[NumRounds + 1];
     if (mode.Equals(EncType.Decrypt))
     {
         Keys = Keys.Reverse().ToArray();
         L[0] = data[0];
         R[0] = data[1];
         for (int i = 1; i < NumRounds + 1; i++)
         {
             L[i] = new BitArray(R[i - 1]);
             BitArray E = Expand(R[i - 1]);
             E    = E.Xor(Keys[i - 1]);
             E    = getChoice(E);
             E    = getPerm(E);
             R[i] = L[i - 1].Xor(E);
         }
         BitArray Cipher = getInverseP(R[16], L[16]);
         Cipher = reverse(Cipher);
         byte[] text = BitArrayToByteArray(Cipher);
         if (Mode == 1)
         {
             plainText += BitConverter.ToString(text);
         }
         else
         {
             plainText += Encoding.ASCII.GetString(text);
         }
     }
     else
     {
         L[0] = data[0];
         R[0] = data[1];
         for (int i = 1; i < NumRounds + 1; i++)
         {
             L[i] = new BitArray(R[i - 1]);
             BitArray E = Expand(R[i - 1]);
             E    = E.Xor(Keys[i - 1]);
             E    = getChoice(E);
             E    = getPerm(E);
             R[i] = L[i - 1].Xor(E);
         }
         BitArray Cipher = getInverseP(R[16], L[16]);
         Cipher = reverse(Cipher);
         byte[] text = BitArrayToByteArray(Cipher);
         if (Mode == 1)
         {
             cipherText += BitConverter.ToString(text);
         }
         else
         {
             cipherText += Encoding.ASCII.GetString(text);
         }
     }
 }
Exemplo n.º 2
0
        private string GetPerf(EncType enc, CombatantData combatant, double encdpshps)
        {
            string job = combatant.GetColumnByName("Job");

            if (job == string.Empty)
            {
                return(string.Empty);
            }

            string perfdpshps = enc == EncType.DPS ? "dps" : "hps";

            EncounterData encounter = combatant.Parent;
            string        zonename  = encounter.ZoneName;
            string        bossname  = encounter.GetStrongestEnemy("YOU");

            PerfKey key  = CreateKey(zonename, bossname);
            dynamic perf = null;

            if (cache.TryGetValue(key, out perf))
            {
                double[] perfarry = (double[])perf[perfdpshps][job];

                if (encdpshps < perfarry[6])
                {
                    return("10-");
                }
                if (encdpshps < perfarry[5])
                {
                    return("10+");
                }
                if (encdpshps < perfarry[4])
                {
                    return("25+");
                }
                if (encdpshps < perfarry[3])
                {
                    return("50+");
                }
                if (encdpshps < perfarry[2])
                {
                    return("75+");
                }
                if (encdpshps < perfarry[1])
                {
                    return("95+");
                }
                if (encdpshps < perfarry[0])
                {
                    return("99+");
                }
                return("100");
            }
            return(string.Empty);
        }
Exemplo n.º 3
0
        public static string LiteralValue(this EncType enctype)
        {
            switch (enctype)
            {
            case EncType.Application_X_WWW: return("application/x-www-form-urlencoded");

            case EncType.Multipart_Form_Data: return("multipart/form-data");

            case EncType.Plaintext: return("text/plain");

            default: throw new ArgumentException();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates the HTML for a form tag.
 /// </summary>
 /// <param name="action">The URL the form submits to</param>
 /// <param name="method">The HTTP method the form submits with</param>
 /// <param name="htmlAttributes">Any HTML attributes that should be applied to the form; specified as an anonymous object</param>
 /// <param name="encType">The encoding type the form uses</param>
 /// <returns>The HTML for the form</returns>
 public static IHtmlString BuildFormTag(string action, FormMethod method, HtmlAttributes htmlAttributes = null, EncType? encType = null)
 {
     var tagBuilder = new TagBuilder("form");
     if (htmlAttributes != null)
         tagBuilder.MergeAttributes(htmlAttributes.Attributes);
     tagBuilder.MergeAttribute("action", action);
     tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
     if (encType.HasValue)
     {
         tagBuilder.MergeAttribute("enctype", encType.Humanize());
     }
     return new HtmlString(tagBuilder.ToString(TagRenderMode.StartTag));
 }
Exemplo n.º 5
0
        private string testEncryption(string input, string key, bool useHash, EncType type = EncType.Encryption)
        {
            string _word     = type == EncType.Encryption ? "En" : "De";
            string _withWord = useHash ? "With" : "Without";

            string ret = "";

            if (type == EncType.Encryption)
            {
                ret = Encrypt.TripleDESEncrypt(input, key, true);
            }
            else
            {
                ret = Encrypt.TripleDESDecrypt(input, key, true);
            }
            Console.WriteLine($"{_word}crypt {_withWord} Hashing: {input} => {ret}");
            Assert.IsNotNull(input);
            Assert.AreNotEqual(input, "");
            Assert.IsNotNull(ret);
            Assert.AreNotEqual(ret, "");
            return(ret);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Decode or Unescape string to original form.
        /// </summary>
        /// <param name="s">Input string.</param>
        /// <param name="typ">Decoding type.</param>
        /// <returns>Decoded string.</returns>
        public static string Decode(this string s, EncType typ)
        {
            switch (typ)
            {
            case EncType.Html:
                return(HttpUtility.HtmlDecode(s));

            case EncType.Url:
                return(HttpUtility.UrlDecode(s));

            case EncType.Dos:
                return(s.Replace(EncDos, false));

            case EncType.Dose:
                return(s.Replace(EncDose, false));

            case EncType.Regex:
                return(Regex.Unescape(s));

            case EncType.Code:
                return(s.Replace(EncCode, false));
            }
            return(s);
        }
 public virtual Nancy.ViewEngines.Razor.IHtmlString BeginForm(string action, FormMethod method, HtmlAttributes htmlAttributes, EncType? enctype)
 {
     return HtmlCreator.BuildFormTag(action, method, htmlAttributes, enctype);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Decode or Unescape string to original form.
        /// </summary>
        /// <param name="s">Input string.</param>
        /// <param name="p">type.</param>
        /// <param name="re">NA.</param>
        private static void Decode(string s, string[] p, bool re)
        {
            EncType t = EncTyp.GetDef(Str(p, 0));

            Print(s.Decode(t));
        }
Exemplo n.º 9
0
 static myWorkArgs newmyWorkArgs(Match m, int maxcount, int count, byte[] oB, int cindex, int score, EncType type, int uid)
 {
     myWorkArgs a = new myWorkArgs();
     a.m = m;
     a.maxcount = maxcount;
     a.count = count;
     a.oB = oB;
     a.cindex = cindex;
     a.score = score;
     a.type = type;
     a.uid = uid;
     return a;
 }
Exemplo n.º 10
0
 static Match newMatch(int len, EncType t)
 {
     Match m = newMatch(len);
     m.type = t;
     return m;
 }
Exemplo n.º 11
0
 public StringBody(EncType encType, string content) : base(encType)
 {
     this.content = content;
 }
Exemplo n.º 12
0
 public ContentBody(EncType encType)
 {
     EncType = encType;
 }
Exemplo n.º 13
0
        private static StreamReader AutoDetect(Stream fs, byte firstByte, byte secondByte, Encoding defaultEncoding)
        {
            int max = (int)Math.Min(fs.Length, 500000);             // look at max. 500 KB

            EncType state          = EncType.ASCII;
            int     sequenceLength = 0;

            byte b = firstByte;

            for (int i = 0; i < max; i++)
            {
                if (i >= 2)
                {
                    b = (byte)fs.ReadByte();
                }
                else if (i == 1)
                {
                    b = secondByte;
                }

                if (b < 0x80)                   // normal ASCII character
                {
                    if (state == EncType.UTF8Sequence)
                    {
                        state = EncType.ASCII;
                        break;
                    }
                }
                else if (b < 0xc0)                   // 10xxxxxx : continues UTF8 byte sequence
                {
                    if (state == EncType.UTF8Sequence)
                    {
                        --sequenceLength;
                        if (sequenceLength < 0)
                        {
                            state = EncType.Error;
                            break;
                        }
                        else if (sequenceLength == 0)
                        {
                            state = EncType.UTF8;
                        }
                    }
                    else
                    {
                        state = EncType.Error;
                        break;
                    }
                }
                else if (b >= 0xc2 && b < 0xf5)                   // beginning of byte sequence
                {
                    if (state == EncType.UTF8 || state == EncType.ASCII)
                    {
                        state = EncType.UTF8Sequence;
                        if (b < 0xe0)
                        {
                            sequenceLength = 1;                             // one more byte following
                        }
                        else if (b < 0xf0)
                        {
                            sequenceLength = 2;                             // two more bytes following
                        }
                        else
                        {
                            sequenceLength = 3;                             // three more bytes following
                        }
                    }
                    else
                    {
                        state = EncType.Error;
                        break;
                    }
                }
                else
                {
                    // 0xc0, 0xc1, 0xf5 to 0xff are invalid in UTF-8 (see RFC 3629)
                    state = EncType.Error;
                    break;
                }
            }

            fs.Position = 0;
            switch (state)
            {
            case EncType.Error:
            case EncType.ASCII:
                // when the file seems to be ASCII or non-UTF8,
                // we read it using the user-specified encoding so it is saved again using that encoding.
                if (defaultEncoding == null || IsUnicode(defaultEncoding))
                {
                    // the file is not Unicode, so don't read it using Unicode even if the
                    // user has choosen Unicode as the default encoding.

                    // If we don't do this, SD will end up always adding a Byte Order Mark to ASCII files.
                    defaultEncoding = Encoding.Default;                             // use system encoding instead
                }
                return(new StreamReader(fs, defaultEncoding, false));

            default:
                return(new StreamReader(fs, false));
            }
        }