public string Crypt(string text, string key, string abc, bool encrypt) { Checker.KeyNull(key); var intKey = Checker.GetKeyInt(key); Checker.TextNull(text); Checker.TextContain(text, abc); // to avoid overflows intKey %= abc.Length; if (!encrypt) { intKey *= -1; } // otherwise invalid index if (intKey < 0) { intKey += abc.Length; } var result = ""; foreach (var ch in text) { for (var j = 0; j < abc.Length; j++) { if (ch == abc[j]) { var temp = (j + intKey) % abc.Length; result += abc[temp]; break; } } } return(result); }