Skip to content

Commit a1ea8a5

Browse files
committed
here
1 parent ca95cef commit a1ea8a5

File tree

5 files changed

+234
-132
lines changed

5 files changed

+234
-132
lines changed

bcrypto.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import glob
22
from bin import *
3+
4+
print("1. Binary\n2. Hex")
5+
ch = input("Chose Encryption method: ")
6+
if ch == "1":
7+
Hex = False
8+
if ch == "2":
9+
Hex = True
310
key = int(input("Key: "))
411
for x in glob.glob("*.txt"):
5-
chypher(x, key)
12+
chypher(x, key, Hex)
613

bin.py

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1+
import re
2+
13
def b2i(binary):
2-
num = str(binary)
3-
ls = num
4+
ls = str(binary)
45
ls = ls[::-1]
56
a = 0
67
fn = 0
78
for x in ls:
89
if int(x) == 1:
910
fn += pow(2, a)
10-
a += 1
11-
else:
12-
a += 1
11+
a += 1
1312
return str(fn)
1413

14+
def i2h(integer):
15+
return hex(integer)[2:]
1516

16-
17-
def i2b(integer):
18-
num = str(integer)
19-
nm = int(num)
20-
fn = ""
21-
while nm != 0:
22-
if nm % 2 == 0:
23-
fn = fn + "0"
24-
nm = nm / 2
25-
nm = int(nm)
17+
def h2i(Hex):
18+
Hex = Hex.upper()
19+
Hex = Hex[::-1]
20+
table = {"A":10, "B":11, "C":12, "D":13, "E":14, "F":15}
21+
a = 0
22+
fn = 0
23+
for x in Hex:
24+
if x in table.keys():
25+
x = table[x]
2626
else:
27-
nm = nm / 2
28-
nm = int(nm)
29-
fn = fn + "1"
30-
while len(fn) < 8:
31-
fn += "0"
32-
fn = fn[::-1]
33-
return str(fn)
27+
x = int(x)
28+
fn += (16**a)*x
29+
a += 1
30+
return fn
31+
32+
def i2b(integer):
33+
return bin(integer)[2:]
3434

35-
def chypher(name, key):
35+
def chypher(name, key, Hex=False):
3636
filename = name
3737
f = open(filename, "r+")
3838
info = f.read()
3939
f = open(filename, "w")
40-
f.truncate()
41-
f.write(te(info, key))
40+
if not Hex:
41+
fn = t2b
42+
else:
43+
fn = t2h
44+
f.write(fn(info, key))
4245
f.close()
43-
print("File crypted.")
4446

45-
def dechypher(name, key):
47+
def dechypher(name, key, Hex=False):
4648
filename = name
4749
f = open(filename, "r+")
4850
info = f.read()
4951
f = open(filename, "w")
5052
f.truncate()
51-
f.write(td(info, key))
53+
if not Hex:
54+
fn = b2t
55+
else:
56+
fn = h2t
57+
f.write(b2t(info, key))
5258
f.close()
53-
print("File decrypted.")
5459

55-
def te(string, key):
60+
def t2b(string, key):
5661
enter = string
5762
fn = ""
5863
for x in enter:
59-
y = ord(x) + key
60-
y = i2b(y)
61-
fn += y
62-
fn += "$"
64+
y = i2b(ord(x) + key)
65+
fn += y + "$"
6366
return fn
6467

65-
def td(binary, key):
66-
enter = binary
67-
mes = ""
68-
part = ""
69-
c = 0
70-
while c < len(enter) - 1:
71-
while enter[c] != "$":
72-
part += enter[c]
73-
c += 1
74-
mes += chr(int(b2i(part)) - key)
75-
c += 1
76-
part = ""
77-
return mes
68+
def b2t(binary, key):
69+
return re.sub(r"(\d+)\$",lambda x: chr(int(b2i(x.group(1))) - key),binary)
70+
71+
def t2h(string, key):
72+
encrypted = ""
73+
for x in string:
74+
encrypted += i2h(ord(x) + key) + "$"
75+
return encrypted
7876

77+
def h2t(Hex, key):
78+
return re.sub(r"(\w+)\$", lambda x: chr(h2i(x.group(1))- key), Hex)

debomber 2.0.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import glob
22
import re
3-
43
from bin import *
4+
5+
print("1. Binary\n2. Hex")
6+
ch = input("Chose Encryption method: ")
7+
if ch == "1":
8+
Hex = False
9+
s2t = b2t
10+
t2s = t2b
11+
s2i = b2i
12+
i2s = i2b
13+
if ch == "2":
14+
Hex = True
15+
s2t = h2t
16+
t2s = t2h
17+
s2i = h2i
18+
i2s = i2h
519
print("1.Key \n2.Beginning \n3.Ending")
620
select = input("Select option: ")
721
if select == "1":
@@ -10,11 +24,12 @@
1024
f = open(x, "r+")
1125
txt = f.read()
1226
f.close()
27+
txt = s2t(txt, key)
1328
print("Text found:\n" + txt)
1429
ch = input("Write text to file?(y/n): ")
1530
if ch == "y":
1631
for x in glob.glob("*.txt"):
17-
dechypher(x, key)
32+
dechypher(x, key, Hex)
1833
print("Decrypted.")
1934
elif select == "2":
2035
ch1 = input("Type first characters of file: ")
@@ -30,20 +45,20 @@
3045
state = False
3146
while True:
3247
if not state:
33-
first_two = re.search(r"(\d+)\$(\d+)\$", check)
34-
first = int(b2i(first_two.group(1)))
35-
second = int(b2i(first_two.group(2)))
48+
first_two = re.search(r"(\w+)\$(\w+)\$", check)
49+
first = int(s2i(first_two.group(1)))
50+
second = int(s2i(first_two.group(2)))
3651
key = first - ord(ch1[0])
37-
check = b2t(check, key)
52+
check = s2t(check, key)
3853
if check[:len(ch1)] != ch1 or key < 0 or state:
3954
if state:
4055
state = False
4156
check = abc
42-
last = b2i(re.search(r"(\d+)\$$", check).group(1))
57+
last = s2i(re.search(r"(\w+)\$$", check).group(1))
4358
last = int(last)
4459
key = last - 36
4560
keys.append(key)
46-
check = b2t(check, key)
61+
check = s2t(check, key)
4762
abc = check
4863
else:
4964
print("Text found:\n{}".format(check))

0 commit comments

Comments
 (0)