7, 31 characters, score 30, safe but possibly broken?
A 7 program is normally just a number, but it can contain whitespace, splitting it into multiple numbers. This submission therefore consists of two numbers (which are implicitly concatenated by the 7 interpreter), and the program likewise takes two numbers as input, via standard input. (The "31 characters" in the header is the total length of the two numbers, plus one separating whitespace character; the digits that make up the numbers are interpreted as octal when used as a program, but decimal when used as an input, and it's the digits that are the same in the two cases, not the actual numbers. Note that it's irrelevant either when treated as a program, or when treated as an input, whether you separate them with a space or a newline; I hope that doesn't invalidate the submission.)
The expected output is the following number (expressed here in decimal, as that's the output format that the 7 interpreter uses):
238363505302130098723162537059
Note that the 7 interpreter linked from the Esolang wiki internally stores numbers in unary, meaning you're unlikely to have enough memory to actually run the program on itself to see what it does. I verified the program via working out its behaviour manually, and testing it on small inputs to verify that it did what I expected it to do. An alternative approach would be to write an interpreter that uses a more efficient method of storing numbers.
Avoiding cracks here was something of a pain, but I'm finally now satisfied that no two numbers other than those in the program itself are capable of producing 238363505302130098723162537059 as output. (EDIT 1 week later: I may have been wrong, depending on how you interpret the question; see below.)
Solution
The original program was:
711170237403706
111723603700633
This program takes two numbers \$x\$ and \$y\$, and calculates the result of the expression \$3xy-y-2\$ (i.e. \$y(3x-1)-2\$). If we perform this calculation at \$x=711170237403706\$ and \$y=111723603700633\$, we get a result of \$238363505302130098723162537059\$ as required.
It was intended that no other input will give the desired result because:
The input must be chosen such that \$y(3x-1)-2=238363505302130098723162537059\$, i.e. \$y(3x-1)=238363505302130098723162537061\$ (adding 2 to both sides). This number is a semiprime, with only two factors: \$111723603700633\$ and \$2133510712211117\$. Only one of these numbers, \$2133510712211117\$, can be expressed in the form \$3x-1\$ (giving \$(3 \times 711170237403706)-1=2133510712211117\$). So we can uniquely identify which number is \$x\$ and which is \$y\$, meaning that only one input works.
However, depending on how you interpret the question, there may be a second input that produces the desired output (thus invalidating this solution):
Unfortunately, there are two multiplicative partitions of a semiprime into two factors: one is to divide it into the two prime factors, but the other is the trivial partition consisting of \$1\$ and the number itself. \$1\$ cannot be written in the form \$3x-1\$ with integer \$x\$, but the desired output can be; thus a potential meta-crack involves giving the input as \$79454501767376699574387512354\$ and \$1\$. However, the first number here involves characters (\$8\$ and \$9\$) which are not in the character set for 7 programs. So if input is restricted to being in the same character set as the program, this solution is valid; but if input containing characters from outside the program's character set is allowed, this solution is invalid.
Explanation
Here's how the intended solution functions:
711170237403706 111723603700633
7 7 7 Stack element separators
111 023 403706 111723603700633 Initial stack elements
111 Number 3, in unary
023 I/O DSL for "input a number"
403706 111723603700633 Main program
(Implicit: execute a copy of the main program element, preserving the original)
40 Swap {023} above {program}, escaping it
3 Do I/O using {023}; pop {program}
0 I/O: numeric
23 Input a number, copying {111} that many times
706 Append "6" to the number (decrementing it)
11 Push two empty stack elements
17236 Push a stack element "23" (unescaped)
0 Escape {23}, consuming an empty element
3 Do I/O using {23}; pop {the element below}
23 Copy the top of stack input many times
7006 Append "66" (i.e. subtract 2)
3 Output {as a number}
3 Exit the program (due to low stack)
The leading 7 and trailing 3 aren't necessary for the program's functionality, they're just there to get the prime factors of the output right. It helps to follow this program if you understand the numeric format; numbers are stored in a unary variant in which 1
and 7
increase the value by 1, and 0
and 6
decrease the value by 1 (thus appending 66
decreases the value by 2, repeating the number multiplies it, and so on). Input's done by repeating a stack element (thus if the stack element is 12345
and the input is \$3\$, the new stack element will be \$123451234512345\$).
1
for itself and0
otherwise \$\endgroup\$1021111143210532105110321051101121171164041581121141051101164011111410040105414410111010061393941
for some other strings. \$\endgroup\$