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
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
| Pair | Times 3 | Does |
|---|---|---|
11 | 33 | Push 1 |
14 | 42 | Pop a and b, push a+b |
17 | 51 | Pop a and b, push b-a |
22 | 66 | Pop a and b, push a*b |
29 | 87 | Pop a and b, push b/a |
30 | 90 | Duplicate the top |
32 | 96 | Start a loop, skipped when the top is 0 |
33 | 99 | End the loop, back while the top is not 0 |
01 | 3 | Print 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.
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
- Stack machines: nine operations on a stack of whole numbers.
- Encoding tricks: the program is a number that has to be decoded first.
Further
See also
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 cipherSource
- 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