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_EncryptDecryptMessage(self): """ uses message and key compression """ plaintext = 'Hello Twitter world in 140 characters.' pub = assemble_publickey(h1_keys['PublicKeyTwitter']) encrypted = encrypt_message(plaintext, pub) # print(encrypted) prk = h1_keys['PrivateKey'] priv = assemble_privatekey((prk['p'], prk['g'], prk['x'], prk['iNumBits'])) decrypted = decrypt_message(priv, encrypted, ) # print(decrypted) assert plaintext == decrypted
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 test_SendEncryptedStatusupdate(self): if userkeys: plaintext = 'Hello Twitter world' # keys pub = assemble_publickey(h1_keys['PublicKeyTwitter']) prk = h1_keys['PrivateKey'] priv = assemble_privatekey((prk['p'], prk['g'], prk['x'], prk['iNumBits'])) encrypted = encrypt_message(plaintext, pub) # Send twitter = Twython(consumer_key, consumer_sec, access_tok, access_token_sec) print(encrypted) send_status_update(twitter, encrypted) # read user_timeline = twitter.get_user_timeline(screen_name='HeteroT1', count=1, exclude_replies=True) lastmessage = user_timeline[0]['text'] decrypted = decrypt_message(priv, lastmessage) print(decrypted) assert plaintext == decrypted