Skip to content

Instantly share code, notes, and snippets.

@RK11
Created July 13, 2012 19:11
Show Gist options
  • Save RK11/3106762 to your computer and use it in GitHub Desktop.
Save RK11/3106762 to your computer and use it in GitHub Desktop.
A VERY unefficient checksum. Works well with strings and tiny files (<1MB)
class myhash:
"""A VERY unefficient checksum. Works well with strings and tiny files (<1MB)"""
hexa = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
def __init__(self, content = ""):
self.content = content
self.checksum = ['0']*32
self.position = 0
self.update(self.content)
def digest_one(self, to_digest):
"""Update the 32 numbers of the checksum with 1 character"""
for a in range(32):
self.checksum[a] = myhash.hexa[((myhash.hexa.index(self.checksum[a])) + ((ord(to_digest)*101)%32) + 149*a*ord(to_digest) + 1337*int(ord(to_digest)*221)/(a+1))%16]
def update(self, content):
"""Update the checksum with a string"""
for a in content:
self.digest_one(a)
def hexdigest(self):
"""Return the checksum"""
string = ''
for e in self.checksum:
string += e
return string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment