From 0fdd2d369ea5b6b4b50b1ed18c5d6c61bf073e79 Mon Sep 17 00:00:00 2001 From: Syed Haseeb Shah Date: Fri, 13 Apr 2018 20:49:38 +0500 Subject: [PATCH] Create Onepad_Cipher.py In one pad algorithm length of key and length of message are equal which results in endless possibilities of false messages on bruteforce. --- ciphers/Onepad_Cipher.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ciphers/Onepad_Cipher.py diff --git a/ciphers/Onepad_Cipher.py b/ciphers/Onepad_Cipher.py new file mode 100644 index 000000000..436592492 --- /dev/null +++ b/ciphers/Onepad_Cipher.py @@ -0,0 +1,28 @@ +class Onepad: + def encrypt(self, text): + '''Function to encrypt text using psedo-random numbers''' + plain = [] + key = [] + cipher = [] + for i in text: + plain.append(ord(i)) + for i in plain: + k = random.randint(1, 300) + c = (i+k)*k + cipher.append(c) + key.append(k) + return cipher, key + + def decrypt(self, cipher, key): + '''Function to decrypt text using psedo-random numbers.''' + plain = [] + for i in range(len(key)): + p = (cipher[i]-(key[i])**2)/key[i] + plain.append(chr(p)) + plain = ''.join([i for i in plain]) + return plain + +if __name__ == '__main__': + c,k = Onepad().encrypt('Hello') + print c, k + print Onepad().decrypt(c, k)