-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorcipher.py
More file actions
68 lines (59 loc) · 1.89 KB
/
Copy pathcolorcipher.py
File metadata and controls
68 lines (59 loc) · 1.89 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
# Name : ColorCipher
# Author : ALIF101XL
# Focus : Learning - Study
# School : STIN.AC.ID
# License : MIT Indonesia
# Deskripsi : Script untuk Encryption/Decryption sebuah file.txt yang berisikan pesan rahasia atau file text. (Hanya File Text)
# Encryption : python3 colorcipher.py enc -i pesan.txt -o out-pesan.txt
# Decryption : python3 colorcipher.py dec -i out-pesan.txt -o hasil.txt
import argparse
COLORS = [
"FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF",
"FF8000","80FF00","00FF80","0080FF","8000FF","FF0080",
"800000","008000","000080","808000","800080","008080",
"FFFFFF","000","C0C0C0","808080","404040","202020",
"FFC0CB","FFA500","ADFF2F","40E0D0","BA55D3","4682B4",
"8B0000","006400","191970","BDB76B","9932CC","20B2AA"
]
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
ENC = {}
DEC = {}
for i in range(len(ALPHABET)):
ENC[ALPHABET[i]] = COLORS[i]
DEC[COLORS[i]] = ALPHABET[i]
def clean(text):
out = []
for ch in text:
u = ch.upper()
if u in ENC:
out.append(u)
return "".join(out)
def encrypt(text):
text = clean(text)
return " ".join(ENC[ch] for ch in text)
def decrypt(text):
parts = text.split()
out = []
for p in parts:
u = p.upper()
if u in DEC:
out.append(DEC[u])
return "".join(out)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("mode", choices=["enc","dec"])
ap.add_argument("-i", required=True)
ap.add_argument("-o", required=True)
args = ap.parse_args()
with open(args.i, "r", encoding="utf-8") as f:
data = f.read()
if args.mode == "enc":
result = encrypt(data)
else:
result = decrypt(data)
with open(args.o, "w", encoding="utf-8") as f:
f.write(result)
print("JANGAN ASAL KLAIM KARYA ORANG YA MEMEK IBUMU. Output:", args.o)
if __name__ == "__main__":
main()