-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathTools.py
34 lines (27 loc) · 790 Bytes
/
Tools.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
class Tools:
@staticmethod
def string_to_binary(input:str):
binary = []
for char in input:
temp = bin(ord(char))[2:]
while(len(temp) < 8):
temp = '0' + temp
binary.append(temp)
return ''.join(binary)
@staticmethod
def string_to_binary_no_concat(input: str):
binary = []
for char in input:
binary.append(bin(ord(char))[2:])
return ''.join(binary)
@staticmethod
def url_to_binary(input:str):
binary = []
url = input.split('/')[-1].split('.')[0]
return url
@staticmethod
def bytes_to_binary(input:bytes):
binary = []
for b in input:
binary.append(f'{b:08b}')
return ''.join(binary)