commit 0870f897bcea1064a892d97c07fc7d4e74f0e80c Author: justuswolff Date: Thu May 9 10:40:57 2024 +0200 first commit, python version diff --git a/py/main.py b/py/main.py new file mode 100644 index 0000000..ae0bb17 --- /dev/null +++ b/py/main.py @@ -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)) + +