diff options
author | VG <vg@devys.org> | 2014-11-28 00:15:19 +0100 |
---|---|---|
committer | VG <vg@devys.org> | 2014-11-28 00:15:19 +0100 |
commit | 753f1d95913915f62d3f18c1075ff1ff08db20eb (patch) | |
tree | 57bc09d9b1b7461facc5c976f96e703a1011c0a9 /identigen.py | |
parent | 483a357e9547aa233db79855d8aa8aef3b3e60e6 (diff) | |
download | pasteme-753f1d95913915f62d3f18c1075ff1ff08db20eb.tar.gz pasteme-753f1d95913915f62d3f18c1075ff1ff08db20eb.tar.bz2 pasteme-753f1d95913915f62d3f18c1075ff1ff08db20eb.zip |
add hash generation from content, and default page display
Diffstat (limited to 'identigen.py')
-rw-r--r-- | identigen.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/identigen.py b/identigen.py new file mode 100644 index 0000000..496d8e0 --- /dev/null +++ b/identigen.py @@ -0,0 +1,34 @@ +import string +import hashlib + +SYLLABUS = ( [ x for x in string.ascii_lowercase if x not in 'aeiouy' ], + [ 'a', 'e', 'i', 'o', 'u', 'y', + 'ai', 'au', 'eu', 'ay', 'ao', 'ay', + 'ey', 'ei', 'eo', 'ou', 'ia', 'io', + 'ua', 'ui' ]) + +def translate(hsh, syllabus=SYLLABUS): + """ + Return a human lisible hash + """ + result = "" + + if len(hsh) % 2 == 1: + hsh = '0' + hsh + + while hsh: + val = int(hsh[0:2], 16) + hsh = hsh[2:] + + result += syllabus[0][val // 20] + result += syllabus[1][val % 20] + + return result + +def generate(content, minsize=8): + return translate( + hashlib.md5(content.encode('utf8')).hexdigest()[0:minsize]) + +if __name__ == '__main__': + import sys + print(generate(sys.argv[1])) |