This commit is contained in:
Hell13Cat
2020-11-04 23:09:59 +03:00
committed by GitHub
parent ae3c82a8b4
commit 0f0b81235f
3 changed files with 100 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
import base64
def to64(data):
e = base64.b64encode(data)
return e
def from64(data):
d = base64.b64decode(data)
return d
def tobin(data):
b = data.encode("UTF-8")
return b
def frombin(data):
b = data.decode("UTF-8")
return b
+62
View File
@@ -0,0 +1,62 @@
import bs64, os, json
def is_folder(ref):
try:
os.listdir(path=ref)
return 1
except:
return 0
def listdict(rf):
list = os.listdir(path=rf)
dirlist = []
for one_l in list:
ref = rf + "/" + one_l
if is_folder(ref) == 1:
dirlist.append(ref)
dirlist.extend(listdict(ref))
return dirlist
def todict(ref):
dict = {}
dirlist = listdict(ref)
dirlist.append(ref)
dict["folders"] = dirlist
filelist = []
count = -1
for one_l in dirlist:
count += 1
list = os.listdir(path=one_l)
for one_f in list:
if is_folder(one_l + "/" + one_f) == 0:
filelist.append({"name":one_f, "id":count, "data": bs64.frombin(bs64.to64(open(one_l+"/"+one_f, "rb").read()))})
dict["files"] = filelist
return dict
def fromdict(dict):
dirlist = dict["folders"]
filelist = dict["files"]
for one_d in dirlist:
os.makedirs("./ready"+str(one_d[1:]), mode=0o777, exist_ok=True)
for one_f in filelist:
bin = bs64.from64(bs64.tobin(one_f["data"]))
file = open("./ready"+str(dirlist[one_f["id"]][1:])+"/"+str(one_f["name"]), "wb")
file.write(bin)
file.close()
def tojson(name, refs):
with open("./cache/"+name, 'w') as fp:
json.dump(todict(refs), fp)
def fromjson(name):
with open("./cache/"+name) as json_file:
data = json.load(json_file)
fromdict(data)
#print(os.listdir(path="."))
#os.makedirs(path, mode=0o777, exist_ok=False)
#print(os.walk(".", topdown=True, onerror=None, followlinks=False))
#print(os.listdir(path="."))
#os.makedirs(path, mode=0o777, exist_ok=False)
#print(os.walk(".", topdown=True, onerror=None, followlinks=False))
+21
View File
@@ -0,0 +1,21 @@
import bs64, os, jcr
from cryptography.fernet import Fernet
print("+--->\n| CrypterPy 1.0\n+--->")
os.makedirs("./cache", mode=0o777, exist_ok=True)
if input("e?>>> ") == "y":
name_r = input("Result name>>> ")
dirs = input("Folder >>>")
jcr.tojson(name_r+".ncf", dirs)
key = Fernet.generate_key()
open("./"+name_r+".kcf", "wb").write(key)
f = Fernet(key)
results = f.encrypt(open("./cache/"+name_r+".ncf", "rb").read())
open("./"+name_r+".ecf", "wb").write(results)
else:
name = input("Name>>> ")
key = open("./"+name+".kcf", "rb").read()
f = Fernet(key)
file = open("./"+name+".ecf", "rb").read()
open("./cache/"+name+".ncf", "wb").write(f.decrypt(file))
jcr.fromjson(name+".ncf")