-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (73 loc) · 2.31 KB
/
main.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
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
69
70
71
72
73
74
75
76
77
import time
import basefwx
import base64
import sys
import pathlib
import os
import time
sys.set_int_max_str_digits(2000000000)
def read(file: str):
with open(file, 'rb') as file:
return file.read()
def read_normal(file: str):
with open(file, 'r') as fil:
return fil.read()
def write(file: str, content: bytes):
with open(file, 'wb'):
pass
f = open(file, 'r+b')
f.write(content)
f.close()
def write_normal(file: str, content: str):
f = open(file, 'w')
f.write(content)
f.close()
def encode(file: str,code: str):
ext = basefwx.b512encode(pathlib.Path(file).suffix, code)
en = str(basefwx.b512encode(base64.b64encode(read(file)).decode('utf-8'), code))
return ext + "A8igTOmG" + en
def decode(content: str, code: str):
extd = basefwx.b512decode(content.split("A8igTOmG")[0],code)
return [base64.b64decode(basefwx.b512decode(content.split("A8igTOmG")[1],code)),extd]
def write_fl(nm,cont):
with open(nm+".fwx", 'wb'):
pass
with open(nm+".fwx", 'r+b') as f:
f.write(cont.encode('utf-8'))
f.close()
def make_decoded(name, cd):
os.chmod(pathlib.Path(name), 0o777)
ct = read_normal(pathlib.Path(name).stem+".fwx")
write(pathlib.Path(name).stem+decode(ct,cd)[1],decode(ct,cd)[0])
os.remove(pathlib.Path(name))
def make_encoded(name, cd):
write_fl(pathlib.Path(name).stem,encode(name,cd))
os.chmod(pathlib.Path(pathlib.Path(name).stem+".fwx"),0)
os.remove(pathlib.Path(pathlib.Path(name)))
inp = input("1. Encode\n2. Decode\nChoose An Option: ")
if inp == "1":
fl = input("File Name: ")
if pathlib.Path(fl).suffix==".fwx":
print("Cant Encode More Than Once For Performance Reasons!")
exit("-1")
if not os.path.isfile(fl):
print("File Does Not Seem To Exist!")
exit("-1")
pd = input("Enter A Password: ")
try:
make_encoded(fl,pd)
except:
print("An Error Occurred!")
if inp == "2":
fl = input("File Name: ")
if not os.path.isfile(fl):
print("File Does Not Seem To Exist!")
exit("-1")
if not pathlib.Path(fl).suffix==".fwx":
print("You Need An Encoded File To Decode It!")
exit("-1")
pd = input("Enter A Password: ")
try:
make_decoded(fl,pd)
except:
print("Incorrect Password!")