Skip to content

Create Onepad_Cipher.py #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ciphers/Onepad_Cipher.py
Original file line number Diff line number Diff line change
@@ -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)