1#Made by myself
2
3import random
4
5text = input ( "Enter text: " )
6
7result = ""
8private_key = ""
9
10for i in text:
11
12 rand = random.randint ( 1, 125 )
13 en = rand + ord ( i )
14 en = chr ( en )
15 en = str ( en )
16
17 private_key = private_key + str ( rand ) + " "
18
19 result = result + en
20
21print ( "\nPublic key:", result )
22print ( "Private key:", private_key )
1import Crypto
2from Crypto.PublicKey import RSA
3from Crypto import Random
4
5random_generator = Random.new().read
6key = RSA.generate(1024, random_generator) #generate public and private keys
7
8publickey = key.publickey # pub key export for exchange
9
10encrypted = publickey.encrypt('encrypt this message', 32)
11#message to encrypt is in the above line 'encrypt this message'
12
13print 'encrypted message:', encrypted #ciphertext
14
15f = open ('encryption.txt', 'w'w)
16f.write(str(encrypted)) #write ciphertext to file
17f.close()
18
19#decrypted code below
20
21f = open ('encryption.txt', 'r')
22message = f.read()
23
24decrypted = key.decrypt(message)
25
26print 'decrypted', decrypted
27
28f = open ('encryption.txt', 'w')
29f.write(str(message))
30f.write(str(decrypted))
31f.close()