code-dumps/py/pyenc.py

36 lines
938 B
Python
Executable File

#!/usr/bin/python3
# This program encrypt/decrypt files with a hard-coded password.
# Original files will be overwritten
import sys
from cryptography.fernet import Fernet
if __name__ == '__main__':
if len(sys.argv) < 3:
print('pyenc [-e|-d] files')
exit(1)
# Static password is used
f = Fernet('PjEba1U9Z5Nm8Irkqi+7+ir9j+YKVSya01aZxRUsVVI=')
if sys.argv[1] == '-e':
for infile in sys.argv[2:]:
file = open(infile, 'rb')
encrypted = f.encrypt(file.read())
file.close()
outfile = open(infile, 'wb')
outfile.write(encrypted)
outfile.close()
if sys.argv[1] == '-d':
for infile in sys.argv[2:]:
file = open(infile, 'rb')
decrypted = f.decrypt(file.read())
file.close()
outfile = open(infile, 'wb')
outfile.write(decrypted)
outfile.close()