-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.py
25 lines (21 loc) · 858 Bytes
/
crypto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3
from Crypto.Cipher import XOR
import base64
import argparse
def encrypt(key, plaintext):
cipher = XOR.new(key)
return base64.b64decode(cipher.encrypt(plaintext))
def decrypt(key, ciphertext):
cipher = XOR.new(key)
return cipher.decrypt(base64.b64decode(ciphertext))
if __name__ == "__main__":
parser = argparse.ArgumentParser("Simple Cryto")
parser.add_argument("-d", "--decrypt", action="store_true")
parser.add_argument("-e", "--encrypt", action="store_true")
parser.add_argument("-k", "--key", required=True, help="Key for encryption/decryption")
parser.add_argument("-t", "--text", required=True, help="Text to encrypt/decrypt")
args = parser.parse_args()
if args.decrypt:
print(decrypt(args.key, args.text))
elif args.encrypt:
print(encrypt(args.key, args.text))