def encrypt_message(plaintext, publickey):
    # encrypt the message
    # privateKey is a elgamal object
    # return elgamal.encrypt(publicKey, plaintext)
    cypher_int = encrypt(publickey, plaintext)
    cypher_compressed = '|'.join(key_compress(int(n)) for n in cypher_int.strip(' ').split(' '))
    return cypher_compressed
 def test_roundtrip_stored_twitter_key(self):
     pub = assemble_publickey(h1_keys['PublicKeyTwitter'])
     prk = h1_keys['PrivateKey']
     priv = assemble_privatekey((prk['p'], prk['g'], prk['x'], prk['iNumBits']))
     c = 0
     while c < 100:
         # message = "My name is Ryan.  Here is some french text:  Maître Corbeau, sur un arbre perché.  Now some Chinese: 鋈 晛桼桾 枲柊氠 藶藽 歾炂盵 犈犆犅 壾, 軹軦軵 寁崏庲 摮 蟼襛 蝩覤 蜭蜸覟 駽髾髽 忷扴汥 "
         message = self.id_generator(500)
         cipher = encrypt(pub, message)
         plain = decrypt(priv, cipher)
         assert message == plain
         c += 1
 def test_roundtrip_plain(self):
     keys = generate_keys()
     priv = keys['privateKey']
     pub = keys['publicKey']
     c = 0
     while c < 1000:
         # message = "My name is Ryan.  Here is some french text:  Maître Corbeau, sur un arbre perché.  Now some Chinese: 鋈 晛桼桾 枲柊氠 藶藽 歾炂盵 犈犆犅 壾, 軹軦軵 寁崏庲 摮 蟼襛 蝩覤 蜭蜸覟 駽髾髽 忷扴汥 "
         message = self.id_generator(500)
         cipher = encrypt(pub, message)
         plain = decrypt(priv, cipher)
         assert message == plain
         c += 1
 def test_simple_encrypt_decrypt(self):
     """
     does not use message and key compression
     """
     plaintext = 'Hello Twitter world in 140 characters.'
     pub = assemble_publickey(h1_keys['PublicKeyTwitter'])
     encrypted = encrypt(pub, plaintext)
     # print(encrypted)
     prk = h1_keys['PrivateKey']
     #ints is a tuple if (p, g, x, iNumBits)
     priv = assemble_privatekey((prk['p'], prk['g'], prk['x'], prk['iNumBits']))
     plaintext = decrypt(priv, encrypted)
     print(plaintext)