-
-
Save artjomb/9a27bbaf400c21398d44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.PublicKey import RSA | |
readsize = 127 | |
writesize = 128 | |
private_key = RSA.generate(writesize * 8) | |
public_key = private_key.publickey() | |
f = open('test04_kahoot.png','rb') | |
p = open('test04_kahoot.png.enc','wb') | |
i = 0 | |
while True: | |
data = f.read(readsize) | |
if not data: | |
break | |
i += 1 | |
enc_data = public_key.encrypt(data, 32)[0] | |
p.write(chr(len(enc_data))) | |
p.write(enc_data) | |
p.close() | |
f.close() | |
f = open('test04_kahoot.png.enc','rb') | |
p = open('test04_kahoot.dec.png','wb') | |
j = 0 | |
while True: | |
length = f.read(1) | |
if not length: | |
break | |
data = f.read(ord(length)) | |
j += 1 | |
dec_data = private_key.decrypt(data) | |
p.write(dec_data[:readsize]) | |
p.close() | |
f.close() | |
print(i, j) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.PublicKey import RSA | |
readsize = 127 | |
writesize = 128 | |
private_key = RSA.generate(writesize * 8) | |
public_key = private_key.publickey() | |
f = open('test04_kahoot.png','rb') | |
p = open('test04_kahoot.png.enc','wb') | |
i = 0 | |
while True: | |
data = f.read(readsize) | |
if not data: | |
break | |
i += 1 | |
enc_data = public_key.encrypt(data, 32)[0] | |
while len(enc_data) < writesize: | |
enc_data = "\x00" + enc_data | |
p.write(enc_data) | |
p.close() | |
f.close() | |
f = open('test04_kahoot.png.enc','rb') | |
p = open('test04_kahoot.dec.png','wb') | |
j = 0 | |
while True: | |
data = f.read(writesize) | |
if not data: | |
break | |
j += 1 | |
dec_data = private_key.decrypt(data) | |
p.write(dec_data[:readsize]) | |
p.close() | |
f.close() | |
print(i, j) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment