Dateien hochladen nach „old things“

master
Justus Jan Nico Wolff 2022-06-06 12:02:40 +02:00
parent 7dcbcae167
commit 1757632246
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
import string
def b2i(binary):
binary = str(binary)
number = int(binary, 2)
return number
def i2b(intin):
intin = int(intin)
number = format(intin, "b")
number = str(number)
while len(number) != 7:
number = "0" + number
return number
def thing2b(thing):
printable = string.printable
library = {}
for i in range(len(printable)):
library[printable[i]] = i
library["ö"] = 100
library["Ö"] = 101
library["Ä"] = 102
library["ä"] = 103
library["Ü"] = 104
library["ü"] = 105
library["ß"] = 106
#print(library)
# 0-99
thing = str(thing)
code = ""
for i in thing:
temp = library[i]
temp = i2b(temp)
code = code + temp
return code
def b2str(binary):
binary = str(binary)
printable = string.printable
library = {}
for i in range(len(printable)):
library[i] = printable[i]
library[100] = "ö"
library[101] = "Ö"
library[102] = "Ä"
library[103] = "ä"
library[104] = "Ü"
library[105] = "ü"
library[106] = "ß"
#print(library)
# 0-99
text = ""
for i in range(int(len(binary)/7)):
temp = ""
for f in range(7*i, 7*i+7):
temp = temp + binary[f]
g = b2i(temp)
text = text + library[g]
return text
# 7
if __name__ == "__main__":
file = open("target.txt", 'r')
file = file.read()
binary2 = thing2b(file)
print("binär = {}".format(binary2))
text = b2str(binary2)
print("text zurück = {}".format(text))
file = open("output.txt", 'w')
file.write(binary2)
file.close()