We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 31e1913 + 0fdd2d3 commit a2b540fCopy full SHA for a2b540f
ciphers/Onepad_Cipher.py
@@ -0,0 +1,28 @@
1
+class Onepad:
2
+ def encrypt(self, text):
3
+ '''Function to encrypt text using psedo-random numbers'''
4
+ plain = []
5
+ key = []
6
+ cipher = []
7
+ for i in text:
8
+ plain.append(ord(i))
9
+ for i in plain:
10
+ k = random.randint(1, 300)
11
+ c = (i+k)*k
12
+ cipher.append(c)
13
+ key.append(k)
14
+ return cipher, key
15
+
16
+ def decrypt(self, cipher, key):
17
+ '''Function to decrypt text using psedo-random numbers.'''
18
19
+ for i in range(len(key)):
20
+ p = (cipher[i]-(key[i])**2)/key[i]
21
+ plain.append(chr(p))
22
+ plain = ''.join([i for i in plain])
23
+ return plain
24
25
+if __name__ == '__main__':
26
+ c,k = Onepad().encrypt('Hello')
27
+ print c, k
28
+ print Onepad().decrypt(c, k)
0 commit comments