public Tuple <PrivateKey, PublicKey> GenerateKeyPair() { /* * q = 11 # selected prime divisor * p = 23 # computed prime modulus: (p-1) mod q = 0 * g = 4 # computed: 1 < g < p, g**q mod p = 1: # and g = h**((p–1)/q) mod p # 4**11 mod 23 = 1: 4194304 mod 23 = 1 # x = 7 # selected: 0 < x < q # y = 8 # computed: y = g**x mod p = 4**7 mod 23 # {23,11,4,8} # the public key: {p,q,g,y} # {23,11,4,7} # the private key: {p,q,g,x} */ var primeQ = 11; var primeP = 23; var randomH = GetRandom(RandomPosition.RandomH, 1, primeQ - 1); var baseG = (int)Math.Pow(randomH, (primeP - 1) / primeQ); var privateX = GetRandom(RandomPosition.RandomX, 1, primeQ - 1); var publicY = (int)Math.Pow(baseG, privateX) % primeP; return(BaseKey.ConstructKeyPair(primeQ, primeP, baseG, privateX, publicY)); }