private string CheckThat(string key, string cipher) { string _result = SomeInstruments.DelSym(key); if (cipher == "Rail_Fence_ENG" || cipher == "Rail_Fence_ALL") { _result = SomeInstruments.DelAlp(_result); try { int.Parse(_result); } catch (FormatException) { _result = ""; } } else if (cipher == "Playfair_ENG" || cipher == "Vigenere_ENG") { _result = SomeInstruments.ForText(_result); } else { _result = SomeInstruments.ForTextRUS(_result); } return(_result.ToLower()); }
static public string DeCipherENG(string FileText, int key) { if (key == 0 || key == 1) { return(FileText); } string text = SomeInstruments.ForText(FileText.ToLower()); int row, period = 2 * (key - 1), k = 0; var a = new string[key, text.Length]; var _DeChipherText = new char[text.Length]; for (int j = 0; j < key; j++) { for (int i = 0; i < text.Length; i++) { row = key - 1 - Math.Abs(key - 1 - i % period); if (row == j) { _DeChipherText[i] = text[k++]; } } } string result = SomeInstruments.CreateText(FileText, string.Join("", _DeChipherText)); return(result); }
static public string Cipher(string FileText, string key) { key = key.ToLower(); var _text = SomeInstruments.ForText(FileText.ToLower()); var _bigRam = new List <string>(); var _resBigRam = new List <string>(); foreach (var item in PrepString(_text)) { _bigRam.Add(item); } string temp, _key = CreateKey(key); int _first, _second, dif; foreach (var item in _bigRam) { if (_key.IndexOf(item[0]) / 5 == _key.IndexOf(item[1]) / 5) // one row { _first = (_key.IndexOf(item[0]) + 1) % 5 == 0 ? _key.IndexOf(item[0]) - 4 : _key.IndexOf(item[0]) + 1; _second = (_key.IndexOf(item[1]) + 1) % 5 == 0 ? _key.IndexOf(item[1]) - 4 : _key.IndexOf(item[1]) + 1; temp = _key[_first].ToString() + _key[_second].ToString(); } else if (_key.IndexOf(item[0]) % 5 == _key.IndexOf(item[1]) % 5) // one column { _first = (_key.IndexOf(item[0]) + 5) % 25; _second = (_key.IndexOf(item[1]) + 5) % 25; temp = _key[_first].ToString() + _key[_second].ToString(); } else // dif angle square { dif = _key.IndexOf(item[0]) % 5 - _key.IndexOf(item[1]) % 5; _first = _key.IndexOf(item[0]) - dif; _second = _key.IndexOf(item[1]) + dif; temp = _key[_first].ToString() + _key[_second].ToString(); } _resBigRam.Add(temp); } string _result = ""; foreach (var item in _resBigRam) { _result += item; } _result = SomeInstruments.CreateText(FileText, _result); return(_result); }
static public string CipherENG(string FileText, int key) { if (key == 0 || key == 1) { return(FileText); } string text = SomeInstruments.ForText(FileText.ToLower()); var _CipherText = new string[key]; int row, period = 2 * (key - 1); for (int i = 0; i < text.Length; i++) { row = key - 1 - Math.Abs(key - 1 - i % period); _CipherText[row] += text[i]; } string result = SomeInstruments.CreateText(FileText, string.Join("", _CipherText)); return(result); }
static public string Cipher(string FileText, string key) { string text = SomeInstruments.ForText(FileText.ToLower()); string result = ""; text.ToLower(); // create a key int _priLenKey = key.Length; while (key.Length < text.Length) { key += alphabet[(alphabet.IndexOf(key[key.Length - _priLenKey]) + 1) % 26]; } // create chiphertext int _index; for (int i = 0; i < text.Length; i++) { _index = (alphabet.IndexOf(text[i]) + alphabet.IndexOf(key[i])) % 26; result += alphabet[_index]; } return(SomeInstruments.CreateText(FileText, result)); }
static public string DeCipher(string FileText, string key) { key = key.ToLower(); var _text = SomeInstruments.ForText(FileText.ToLower()); var _bigRam = new List <string>(); var _resBigRam = new List <string>(); foreach (var item in PrepString(_text)) { _bigRam.Add(item); } string temp, _key = CreateKey(key); int _first, _second, dif; foreach (var item in _bigRam) { if (_key.IndexOf(item[0]) / 5 == _key.IndexOf(item[1]) / 5) // one row { _first = _key.IndexOf(item[0]) % 5 == 0 ? _key.IndexOf(item[0]) + 4 : _key.IndexOf(item[0]) - 1; _second = _key.IndexOf(item[1]) % 5 == 0 ? _key.IndexOf(item[1]) + 4 : _key.IndexOf(item[1]) - 1; temp = _key[_first].ToString() + _key[_second].ToString(); } else if (_key.IndexOf(item[0]) % 5 == _key.IndexOf(item[1]) % 5) // one column { _first = _key.IndexOf(item[0]) - 5 < 0 ? 25 - 5 + _key.IndexOf(item[0]) : _key.IndexOf(item[0]) - 5; _second = _key.IndexOf(item[1]) - 5 < 0 ? 25 - 5 + _key.IndexOf(item[1]) : _key.IndexOf(item[1]) - 5; temp = _key[_first].ToString() + _key[_second].ToString(); } else // dif angle square { dif = _key.IndexOf(item[0]) % 5 - _key.IndexOf(item[1]) % 5; _first = _key.IndexOf(item[0]) - dif; _second = _key.IndexOf(item[1]) + dif; temp = _key[_first].ToString() + _key[_second].ToString(); } _resBigRam.Add(temp); } string _result = ""; foreach (var item in _resBigRam) { _result += item; } if (_result[_result.Length - 1] == 'x') { _result = _result.Substring(0, _result.Length - 1); } string _temp = ""; for (int i = 0; i < _result.Length; i++) { if (!(_result[i] == 'x' && _result[i - 1] == _result[i + 1])) { _temp += _result[i]; } } _result = SomeInstruments.CreateText(FileText, _temp); return(_result); }