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)
def decrypt_message(privatekey, cypher_compressed):
    # try to decrypt message
    cypher_int = ' '.join(str(key_expand(c)) for c in cypher_compressed.split('|')) + ' '
    return decrypt(privatekey, cypher_int)