Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Cipher Dict by Matt_Leroy
def get_cipher(plain):
number = str(int.from_bytes(plain.encode()))
up = 1
seq = number[:1]
seqs = []
for i in range(1, len(number)):
if int(number[i]) * up > int(number[i - 1]) * up:
seq += number[i]
else:
up = -up
seqs.append(seq)
seq = number[i]
seqs.append(seq)
return encode(seqs, 0)[0]
def encode(seqs, i):
if not seqs[i:]:
return {}, i
out = {}
index = sum(len(x) for x in seqs[:i])
for k, j in enumerate(seqs[i]):
out[int(j)], i = encode(seqs, index + k + 1)
return out, i
May 28, 2023
Comments: