Restricted Node Kipple esolang builds a checksum from addition alone

pwn
flag L3m0n{a4a0c52c728e291597439519bd7efaaa}

"A new node. A few restrictions. Something doesn't quite add up." A live-only service, no handout. Connecting reveals a Kipple interpreter (an obscure 2003 esolang) that pushes 16 random bytes onto an input stack, runs whatever program you submit, and compares what ends up on the output stack against a weighted checksum of those 16 bytes. A text filter rejects any operator glued directly onto the i (input) stack name - i>, i+, (i, all blocked outright.

Hint

Kipple's + operator doesn't consume what it adds. What happens if you add a stack's own top value to itself, repeatedly?

Kipple in thirty seconds

Kipple has 26 named stacks (a-z), the special input/output stacks i/o, @ to convert a number to its decimal digits, and (stack ...) to loop while a stack is non-empty. Pinning down exactly what each operator does, directly against the live node (safer than trusting memory of an obscure language):

output
a < 5 a+0 a > o a > o a > o a > o        -> 00 00 05 05
     a = {5,5}  -- a+0 appended a copy of the top; the empty pops after give 0x00
a < 3 a < 4 a+a a > o a > o a > o a > o  -> 00 00 03 07
     a = {3,7}  -- a+a folded the top into the one below, leaving the original on top
0>c a < 5 a+0 a+0 a+a a+a c+a c>@ (@>o)  -> "15"
     3 x 5, printed in decimal via @

Insight

a+0 pushes a second copy of a's current top without popping the first - so w-1 repeats of a+0 turn one value into w identical copies sitting on the stack. a+a then folds two adjacent copies into their sum without consuming the stack underneath, which is exactly how "multiply a byte by a small integer weight" gets built entirely out of unary addition operators, with no multiplication primitive required at all.

Beating the filter

The filter only blocks an operator glued directly onto i - so every use of i just needs a space before the next character (i > a, never i>a). Reading one byte off i, duplicating it w-1 times with a+0, folding those copies together with a+a, and adding the result into an accumulator stack c builds the whole weighted sum one input byte at a time, entirely in text the filter is happy with:

python
1WEIGHTS = [3, 2, 1, 4, 3, 2, 4, 1, 2, 3, 1, 4, 2, 4, 1, 3]
2CONST = 91537
3
4def program(weights=WEIGHTS, const=CONST):
5    parts = ["%d>c" % const]
6    for w in reversed(weights):            # i is a stack: bytes come out LIFO
7        parts.append("i > a" + " a+0" * (w - 1) + " a+a" * (w - 1) + " c+a")
8    return " ".join(parts) + " c>@ (@>o)"

Pitfall

The 16 random bytes come off i in LIFO order (last pushed, first popped), so the weight list has to be walked in reverse to pair the right weight with the right byte. Getting that order backwards produces a checksum that's wrong in a way that still looks plausible - every weight gets applied to some byte, just the wrong one.

Running the generated program against the live node:

output
L3m0n{a4a0c52c728e291597439519bd7efaaa}

Note

Worth knowing before chasing a stale port: the flag is a property of the node, not of the random input it hands out each connection - running the identical program against the same node repeatedly returns the identical flag every time, even though the 16 bytes on i differ on every connection. But a port that has rotated away still answers TCP and still happily prints its old flag, which the platform then rejects. Do not cache a port once found - always re-check which instance is currently the one the platform is actually tracking before trusting a connection's output.