Skip to content

Commit

Permalink
add padding to text, update gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainL972 committed Feb 6, 2020
1 parent a0dd364 commit 988580b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
build/
a.out
rsa.so
privkey.json
__pycache__
*.pyc
24 changes: 21 additions & 3 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,28 @@ def getKey():
key = createKey()
return key

def padText(hexa):
result = []
for i in range(0, len(hexa),7):
result.append(hexa[i:i+7])
return result

def unpadText(list):
result = ""
for part in list:
result += part
return result

def encryptText(key, text):
hexa = binascii.hexlify(text.encode())
return rsa.encrypt(hexa, key["e"], key["n"]).encode()
hexa = padText(hexa)
result = []
for part in hexa:
result.append(rsa.encrypt(part, key["e"], key["n"]).encode())
return result

def decryptText(key, cypher):
hexa = rsa.decrypt(cypher, key["d"], key["n"])
return binascii.unhexlify(hexa).decode()
result = []
for part in cypher:
result.append(rsa.decrypt(part, key["d"], key["n"]))
return binascii.unhexlify(unpadText(result)).decode()

0 comments on commit 988580b

Please sign in to comment.