first commit, python version
commit
0870f897bc
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue