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); } } }
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); }
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(); } }
/// <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)); }
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); }
/// <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); }
/// <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)); }
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; }
static Match newMatch(int len, EncType t) { Match m = newMatch(len); m.type = t; return m; }
public StringBody(EncType encType, string content) : base(encType) { this.content = content; }
public ContentBody(EncType encType) { EncType = encType; }
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)); } }