MCPcopy Create free account
hub / github.com/ActiveState/code / babble

Function babble

recipes/Python/578319_bubblebabble/recipe-578319.py:44–76  ·  view source on GitHub ↗

Compute bubble babble for input buffer. >>> babble('') 'xexax' >>> babble('1234567890') 'xesef-disof-gytuf-katof-movif-baxux' >>> babble('Pineapple') 'xigak-nyryk-humil-bosek-sonax' >>> babble('lol') 'xirak-zorex' >>> import hashlib >>> babble(hashlib.sha1('l

(digest, seed=1)

Source from the content-addressed store, hash-verified

42
43
44def babble(digest, seed=1):
45 """ Compute bubble babble for input buffer.
46 >>> babble('')
47 'xexax'
48 >>> babble('1234567890')
49 'xesef-disof-gytuf-katof-movif-baxux'
50 >>> babble('Pineapple')
51 'xigak-nyryk-humil-bosek-sonax'
52 >>> babble('lol')
53 'xirak-zorex'
54 >>> import hashlib
55 >>> babble(hashlib.sha1('lol').digest())
56 'xibaf-nanob-fyzib-bikyh-davot-zotos-ryzah-decir-lucus-donoz-poxex'
57 >>> babble([70, 85, 129, 199])
58 'xicih-habes-laxex'
59 >>> babble(0)
60 'xebax'
61 """
62 ret = 'x'
63 x = y = None
64 iters = [maybe_ord(digest)] * 2
65 for x,y in itertools.izip_longest(fillvalue=None, *iters):
66 ret += vowels[(((x >> 6) & 3) + seed) % 6]
67 ret += consonants[(x >> 2) & 15]
68 ret += vowels[((x & 3) + (seed / 6)) % 6]
69 if y is not None:
70 seed = ((seed * 5) + (x * 7) + y) % 36
71 ret += consonants[(y >> 4) & 15]
72 ret += '-'
73 ret += consonants[y & 15]
74 if y is not None or x is None:
75 ret += vowels[seed % 6] + 'x' + vowels[seed / 6]
76 return ret + 'x'
77
78if __name__ == '__main__':
79 import doctest

Callers

nothing calls this directly

Calls 1

maybe_ordFunction · 0.85

Tested by

no test coverage detected