-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodeLN.py
More file actions
37 lines (29 loc) · 1.05 KB
/
EncodeLN.py
File metadata and controls
37 lines (29 loc) · 1.05 KB
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
#!/usr/bin/python3
# encode file by Di4rDev
import string
import random
def encodeLNumber(input_string):
long_number = int.from_bytes(input_string.encode(), byteorder='big')
encoded_string = f"/#{long_number}"
return encoded_string
def decodeLNumber(encoded_string):
if not encoded_string.startswith("/#"):
return "The encoded string is not in the correct format"
long_number = int(encoded_string[2:])
decoded_bytes = long_number.to_bytes((long_number.bit_length() + 7) // 8, byteorder='big')
decoded_string = decoded_bytes.decode('utf-8')
return decoded_string
def go():
print("----------------------\n 1: encode\n 2: decode\n Input 1 or 2!\n----------------------\n")
chon = str(input("Input: "))
if chon == "1":
code = str(input("Input code to encode: "))
en = encodeLNumber(code)
print(en)
if chon == "2":
code = (input("Input code to decode: "))
de = decodeLNumber(code)
print(de)
if chon != "1" and chon != "2":
go()
go()