Exponentiation cipherExponentiation ciphers use a form of \(C=M^e\pmod p\) to encrypt and decrypt a message (\(M\)) using a key of \(e\) and a prime number \(p\). It is used in Pohlig-Hellman and RSA: |
Examples
The following are some examples:
- message = 5, e=5, p = 53. Try. This should give \(5^5 \pmod 53 = 3125 \pmod 53 = 51\).
- message = 4, e=11, p = 79. Try. This should give \(4^11 \pmod 79 = 4194304 \pmod 79 = 36\).
- message = 101, e=7, p = 293. Try. This will give an answer of 107213535210701 (mod 293).
Outline
First we determine create a prime number, such as:
p = 5
The cipher is:
Cipher = Message^e mod p
For example if we have a Message of 2 and e of 3 we get:
Cipher = 2^3 mod 5 = 3
Code
Outline code:
public static string encr2(UInt64 m, UInt64 e, UInt64 p) { Microsoft.SolverFoundation.Common.BigInteger message = (Microsoft.SolverFoundation.Common.BigInteger)m; Microsoft.SolverFoundation.Common.BigInteger eval = (Microsoft.SolverFoundation.Common.BigInteger)e; Microsoft.SolverFoundation.Common.BigInteger pval = (Microsoft.SolverFoundation.Common.BigInteger)p; Microsoft.SolverFoundation.Common.BigInteger val1 = Microsoft.SolverFoundation.Common.BigInteger.Power(m, eval) ; Microsoft.SolverFoundation.Common.BigInteger val = val1 % p; string rtn = String.Format("Result: {0}\n\\Message: {1}\nExp: {2}\nPrime: {3}\nMessage^Exp: {4}", val.ToString(),m.ToString(), e.ToString(), p.ToString(), val1.ToString()); return rtn; }
The Python equivalent is:
message = input('Enter message: ') e = input('Enter exponent: ') p = input('Enter prime ') cipher = (int(message) ** int(e)) % int(p) print (f"{message}^{e} (mod {p})={cipher}")