| 4 | |
| 5 | |
| 6 | class Onepad: |
| 7 | def encrypt(self, text): |
| 8 | '''Function to encrypt text using psedo-random numbers''' |
| 9 | plain = [ord(i) for i in text] |
| 10 | key = [] |
| 11 | cipher = [] |
| 12 | for i in plain: |
| 13 | k = random.randint(1, 300) |
| 14 | c = (i+k)*k |
| 15 | cipher.append(c) |
| 16 | key.append(k) |
| 17 | return cipher, key |
| 18 | |
| 19 | def decrypt(self, cipher, key): |
| 20 | '''Function to decrypt text using psedo-random numbers.''' |
| 21 | plain = [] |
| 22 | for i in range(len(key)): |
| 23 | p = int((cipher[i]-(key[i])**2)/key[i]) |
| 24 | plain.append(chr(p)) |
| 25 | plain = ''.join([i for i in plain]) |
| 26 | return plain |
| 27 | |
| 28 | |
| 29 | if __name__ == '__main__': |