public static string DecryptPolynomialBlockCipher(List <List <double> > coeffs, int key, int blockSize = 2) { string plainText = ""; if (key.IsEven()) { key++; } foreach (var coeff in coeffs) { string cipherPart = PolynomialCipher.DecodePolynomial(coeff, key); plainText += cipherPart.Replace("Z", " ").Replace("X", "-").Replace("Q", "."); } return(plainText); }
public static string EncryptPolynomialBlockCipher(string plainText, int key, int blockSize = 2) { string cipherText = ""; // Even keys prevent the characters from being decrypted in the proper order if (key.IsEven()) { key++; } foreach (var raw in Common.SplitIntoNGrams(plainText, blockSize)) { string ngram = raw.Replace(" ", "Z").Replace("-", "X").Replace(".", "Q"); cipherText += PolynomialCipher.CoeffsToPolynomial(PolynomialCipher.EncryptString(ngram, key)) + "\r\n"; } return(cipherText); }