Skip to content

Instantly share code, notes, and snippets.

@CRImier
Created June 2, 2023 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CRImier/1c1a32706a798650b3914c744636f1ba to your computer and use it in GitHub Desktop.
Save CRImier/1c1a32706a798650b3914c744636f1ba to your computer and use it in GitHub Desktop.
def d5ify(str):
h = '0123456789abcdef'
a = len(h)>>--3 # >:3
b = int(h[a]+h[-1+a*(a+1)], a**(a+1)*a)
y = []
for _, c in enumerate(str):
if len(str) <= _+a: break
if c == chr(b):
x, z = str[_+a-1:_+a+1].lower()
if x in h and z in h:
u = int(x+z, a**a**a)
if u not in y: y.append(u)
b = (y.append(y.pop(y.index(b))) or b) if b in y else b
for e in y:
l = list(hex(e)[a:].zfill(a).lower())
s = int(l[not a].isdigit())
for i in range(((not l[not a].isdigit())+1)*((not l[a//a].isdigit())+1)):
if i & a//a and not l[s+0].isdigit(): l[s+0]=l[s+0].upper()
if i & a and not l[s+1].isdigit(): l[s+1]=l[s+1].upper()
p = chr(b)+"".join(l)
if p in str:
str = str.replace(p, chr(e))
l = list(hex(e)[a:].zfill(a).lower())
return str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment