Пример #1
0
 /// <summary>
 /// Key = (a,b)
 /// Modulo = m
 /// E(x) = (ax + b) mod m
 /// </summary>
 /// <param name="plaintext"></param>
 /// <returns>Ciphertext</returns>
 public override string Encryption(string plaintext, int start = 'A') =>
 new String(plaintext.ToCharArray().Select(x => Convert.ToChar(
                                               (((PrivateKey.ElementAt(0) * (x - start) + PrivateKey.ElementAt(1))) % Mod.Modulo)
                                               )).ToArray());
Пример #2
0
 /// <summary>
 /// Key = (a,b)
 /// Modulo = m
 /// D(y) = Inverse(a,m) * (y - b) mod m
 /// </summary>
 /// <param name="ciphertext"></param>
 /// <returns></returns>
 public override string Decryption(string ciphertext, int start = 'A') =>
 new String(ciphertext.ToCharArray().Select(y => Convert.ToChar(
                                                (Mod.PositiveMod(Mod.Inverse(PrivateKey.ElementAt(0)) *
                                                                 (y - start - PrivateKey.ElementAt(1))) + start)
                                                )).ToArray());
Пример #3
0
 /// <summary>
 /// D(y) = y^a mod n
 /// </summary>
 /// <param name="ciphertext"></param>
 /// <returns></returns>
 public override string Decryption(string ciphertext, int start = 0) =>
 new String(ciphertext.ToCharArray().Select(y => Convert.ToChar(
                                                start + BigInteger.ModPow(y - start, PrivateKey.ElementAt(2), PublicKey.ElementAt(0))
                                                )).ToArray());