public string Decrypt(string cipherText) { StringBuilder clear = new StringBuilder(); for (int i = 0; i < cipherText.Length; i += 2) { int c1 = KeySquare1.IndexOf(cipherText[i]) % 5; int r1 = KeySquare1.IndexOf(cipherText[i]) / 5; int c2 = KeySquare2.IndexOf(cipherText[i + 1]) % 5; int r2 = KeySquare2.IndexOf(cipherText[i + 1]) / 5; clear.Append(alphabet[5 * r1 + c2]); clear.Append(alphabet[5 * r2 + c1]); } return(clear.ToString()); }
public string Decrypt(string encodedText) { StringBuilder plainText = new StringBuilder(); for (int i = 0; i < encodedText.Length; i += 2) { var i0 = KeySquare1.GetIndex(encodedText[i]); var row0 = i0 / SQUARE_SIZE; var col0 = i0 % SQUARE_SIZE; var i1 = KeySquare2.GetIndex(encodedText[i + 1]); var row1 = i1 / SQUARE_SIZE; var col1 = i1 % SQUARE_SIZE; plainText.Append(ReferenceAlphabet[row0 * SQUARE_SIZE + col1]); plainText.Append(ReferenceAlphabet[row1 * SQUARE_SIZE + col0]); } return(plainText.ToString()); }