-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezku_V1.py
110 lines (88 loc) · 2.94 KB
/
ezku_V1.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import string
def decrypt():
def cipher(code):
code = [*code.split()]
binary_list = []
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
binary_list = []
high_lenght = 0
for i in range(len(code)):
code_converted = [*f"{int(code[i]):#010b}"[2:]]
code_converted.reverse()
if len(code_converted) > high_lenght:
high_lenght = len(code_converted)
for i in range(len(code)):
code_converted = [*f"{int(code[i]):#010b}"[2:]]
code_converted.reverse()
while len(code_converted) != high_lenght:
code_converted.append("0")
#print("".join(code_converted))
binary_list.append("".join(code_converted))
byte_index = high_lenght - 1
new_byte = []
final_byte = []
#create new set of byte with the last bit of each byte, then the one before the last, and etc...
for i in range(high_lenght):
for i in range(len(binary_list)):
bi = [*binary_list[i]]
new_byte.append(bi[byte_index])
#print("".join(new_byte))
byte_index -= 1
final_byte.append("".join(new_byte))
new_byte.clear()
for i in range(len(final_byte)):
code = int(final_byte[i], 2)
if code != 0:
decrypted_code = alphabet[code - 1]
print(Fore.GREEN + str(decrypted_code), end="")
#break the word in an array with each letters
code = str(input(Fore.WHITE + "Enter code : "))
if len(code.split()) < 2:
cipher(code)
else:
code = code.split("/")
#print(code)
for i in range(len(code)):
cipher(code[i])
print(" ", end="")
def encrypt():
def cipher(word):
word = [*word]
binary_list = []
for i in range(len(word)):
if word[i].isalpha():
binary = string.ascii_lowercase.index(word[i]) + 1
#print(f"{binary:#010b}"[2:])
binary_list.append(f"{binary:#010b}"[2:])
else:
#do nothing
print("", end="")
byte_index = 7
new_byte = []
final_byte = []
#create new set of byte with the last bit of each byte, then the one before the last, and etc...
for i in range(byte_index):
for i in range(len(binary_list)):
bi = [*binary_list[i]]
new_byte.append(bi[byte_index])
byte_index -= 1
final_byte.append("".join(new_byte))
new_byte.clear()
def sum(l):
total = 0
for val in l:
total = total + int(val)
return total
#reconvert binary to numbers
for i in range(len(final_byte)):
code = int(final_byte[len(final_byte) - 1 - i], 2) #reverse the order of the answer
print(Fore.GREEN + str(code), end=" ")
#break the word in an array with each letters
word = str(input(Fore.WHITE + "Enter word : ").lower())
if len(word.split()) < 2:
cipher(word)
else:
word = word.split()
for i in range(len(word)):
cipher(word[i])
print("/ ", end="")