first commit, python version

main
Justus Jan Nico Wolff 2024-05-09 10:40:57 +02:00
commit 0870f897bc
1 changed files with 57 additions and 0 deletions

57
py/main.py 100644
View File

@ -0,0 +1,57 @@
import string
characters = list(string.printable)
class hasher:
def tobin(self, target):
return bin(int(target))[2:]
def todec(self, target):
return int("0b"+target, 2)
def toblocks(self, target, size=4):
blocks = []
temp = ""
for i in range(len(target)):
index = i
i = target[i]
temp = temp + i
if (index+1)%size == 0 and index != 0:
blocks.append(temp)
temp = ""
if len(temp) != 0: blocks.append(temp)
return blocks
def strbin(self, target):
temp = ""
for i in target:
temp = temp + str(characters.index(i)%2)
return temp
def prep(self, target):
blocks = self.toblocks(target)
out = ""
for i in blocks:
out = out + self.strbin(i)
return out
def ohash(self, target):
target = self.prep(target)
target = self.todec(target)
return characters[target%len(characters)]
def mhash(self, target):
target = self.prep(target)
target = self.toblocks(target)
out = ""
for i in target:
i = self.todec(i)
out = out + characters[i%len(characters)]
return out
if __name__ == "__main__":
hashing = hasher()
target = "Hello, World!"
print("single character hash: "+hashing.ohash(target))
print("string hash: "+hashing.mhash(target))