Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib, listcomp
- from string import printable as h
- from string import hexdigits as hd
- from string import letters as l
- md5 = hashlib.md5
- sha1 = hashlib.sha1
- sha224 = hashlib.sha224
- sha256 = hashlib.sha256
- sha384 = hashlib.sha384
- sha512 = hashlib.sha512
- modes = {
- md5: 32,
- sha1: 40,
- sha224: 56,
- sha256: 64,
- sha384: 96,
- sha512: 128
- }
- def stencode(stuff, alg):
- if alg in modes:
- return ''.join([alg(i).hexdigest() for i in stuff])
- else: raise Exception, "Not an Algorithm"
- def stcondense(stuff, alg):
- """For hashing only! cannot be docoded.. I think..."""
- if alg in modes:
- content = ''.join([alg(i).hexdigest() for i in stuff])
- lettermap = [[i for i in hd].index(o) for o in content]
- (p1, p2) = listcomp.halflist(lettermap)
- summap = [sum(i) for i in zip(p1, p2)]
- return ''.join([l[i] for i in summap])
- else: raise Exception, "Not an Algorithm"
- def stmean(stuff, alg):
- """hashes all characters in string, averages their index value, generates string based on values"""
- if alg in modes:
- parts = []
- content = [alg(i).hexdigest() for i in stuff]
- for i in content:
- parts.append(tuple([hd.index(ab) for ab in i]))
- result = [sum(y) / len(y) for y in zip(*parts)]
- return ''.join([hd[i] for i in result])
- else: raise Exception, "Not an Algorithm"
- def stdecode(stuff, alg):
- if alg in modes:
- stuff = listcomp.chop(stuff, modes[alg])
- completed = []
- for i in stuff:
- for a in h:
- if alg(a).hexdigest() == i:
- completed.append(a)
- return ''.join(completed)
- else: raise Exception, "Not an Algorithm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement