esolang

Cipher

The whole program is one number. Take 5, divide by 17, and the digits left over are the code.

ChuckEsoteric08 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 2

The idea

ChuckEsoteric08 made Cipher, a small stack language hidden inside arithmetic. The source is a single decimal number. Take 5 from it and divide by 17, then read the digits of the result two at a time. Each pair, times 3, names an operation.

The machine

PairTimes 3Does
1133Push 1
1442Pop a and b, push a+b
1751Pop a and b, push b-a
2266Pop a and b, push a*b
2987Pop a and b, push b/a
3090Duplicate the top
3296Start a loop, skipped when the top is 0
3399End the loop, back while the top is not 0
013Print the top as a number

The specification does not say what goes between printed numbers, so this implementation prints nothing between them. Printing leaves the top on the stack; the countdown only works that way.

Example

The first number is 17 times 11111401, plus 5.
Expected: 4321
Expected: 16

The first number is 17 times 11111401, plus 5. Its pairs are push 1, push 1, add, print. The countdown builds 4 from ones, then loops, printing the top and taking 1 until it reaches 0. The last number squares 2 twice.

Patterns it teaches

Further

Stack-based

Write your own in Run Convert a program from Cipher

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: cipher.

Command line

shib run cipher -e '188893822'
shib manual cipher

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/cipher.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org