Find the Translation Table Given two strings, find the translation table (substitution cipher) between the two, if the translation is not possible, output false. The answer must be minimized and created from left-to-right. The first character to be translated between words must be the first in the translation table. In addition to this, any letter that is not translated (in the same place as it was originally), should NOT be in the translation table.
Probably most easily defined through examples:
Valid Cases
&quot;bat&quot;, &quot;sap&quot; =&gt; [&quot;bt&quot;,&quot;sp&quot;]

Notice the ordering, an output of [&quot;tb&quot;,&quot;ps&quot;] is not valid for this challenge.
&quot;sense&quot;, &quot;12n12&quot; =&gt; [&quot;se&quot;,&quot;12&quot;]

Notice how the n isn't translated because it is a 1 to 1 relation.
&quot;rabid&quot;, &quot;snail&quot; =&gt; [&quot;rabd&quot;,&quot;snal&quot;]

Notice how the i isn't translated because it is a 1 to 1 relation.
&quot;ass&quot;, &quot;all&quot; =&gt; [&quot;s&quot;,&quot;l&quot;]

A is not included, it stays the same, s can map to l due to pattern match.
&quot;3121212&quot;, &quot;ABLBLBL&quot; =&gt; [&quot;312&quot;,&quot;ABL&quot;]

Matches pattern perfectly.
Falsy Cases
&quot;banana&quot;, &quot;angular&quot; =&gt; false

(not the same length, impossible).
&quot;animal&quot;, &quot;snails&quot; =&gt; false

(each character can only be used ONCE on each side of the translation).
&quot;can&quot;,&quot;cnn&quot; =&gt; false

(n is implicitly used in translation, therefore, defining a translation table with n-&gt;a would be invalid)
Thusly, [aimal,sails] is an invalid answer, making this falsy.
&quot;a1&quot;, &quot;22&quot; =&gt; false

See &quot;caveats&quot;, this is listed as falsy. In this case, it's because a and 1 cannot both map to 2. (Each character can only be used ONCE on each side of the translation).

This answer seems to be a good benchmark: https://codegolf.stackexchange.com/a/116807/59376
If you have questions about the functionality of two unlisted word pairs, defer to this implementation.

I/O rules

Input may be as a 2 element array or as 2 separate inputs.
Output can be as an array or newline/space delimited, similar to how I have it shown.
False output may be 0, -1 or false. Erroring/Empty output is also fine.
You are guaranteed that a will not equal b and neither a nor b will be empty.
a and b are printable-ASCII-only sequences of letters.

Caveats

Translations must occur from left to right, see example 1.
You must not output characters that remain the same.
Your program may only take in two strings a and b.
Each character can only be used ONCE on each side of the translation. This is what makes the translation from snails to animals impossible.
Recursive replaces should not occur. Example of recursive replace: &quot;a1&quot;,&quot;22&quot;-&gt;[a1,12] where a is first replaced by a 1, then both resultant 1's are replaced with 2's. This is not correct, assume all translations occur independent of each other, meaning this is falsy. Meaning: &quot;a1&quot; with translation table of [a1,12] evaluates to 12 (not 22)
PHP >=7.1, 130 Bytes

18 Bytes saved by @Titus

for([,$x,$y]=$argv;a&amp;$o=$y[$i];)$o==($p=$x[$i++])?:$k[$c[$p]=$o]=$p;echo$y==strtr($x,$c)&amp;$x==strtr($y,$k)?join($k)." ".join($c):0;


Testcases

Expanded

for([,$x,$y]=$argv;a&amp;$o=$y[$i];)
$o==($p=$x[$i++])?:$k[$c[$p]=$o]=$p; # if char string 1 not equal char string 2 make key=char1 value=char2 and key array
echo$y==strtr($x,$c) # boolean replacement string 1 equal to string 2
    &amp;$x==strtr($y,$k) # boolean replacement string 2 equal to string 1
    ?join($k)." ".join($c) # output for true cases
:0; #Output false cases


PHP >=7.1, 148 Bytes

prints 0 for false Output true as string


for([,$x,$y]=$argv;a&amp;$o=$y[$i];$i++)$x[$i]==$o?:$c[$x[$i]]=$o;echo$y==strtr($x,($f=array_flip)($k=$f($c)))&amp;$x==strtr($y,$k)?join($k)." ".join($c):0;


Testcases

Expanded


for([,$x,$y]=$argv;a&amp;$o=$y[$i];$i++)
$x[$i]==$o?:$c[$x[$i]]=$o; # if char string 1 not equal char string 2 set key=char1 value=char2
echo$y==strtr($x,($f=array_flip)($k=$f($c))) # boolean replacement string 1 equal to string 2
&amp;$x==strtr($y,$k) # boolean replacement string 2 equal to string 1
    ?join($k)." ".join($c) # output for true cases
:0; #Output false cases


PHP >=7.1, 131 Bytes

The second answer can be shorted to this if associative arrays are allowed

prints 0 for false Output true as associative array instead of string


for([,$x,$y]=$argv;a&amp;$o=$y[$i];$i++)$x[$i]==$o?:$c[$x[$i]]=$o;print_r($y==strtr($x,($f=array_flip)($f($c)))&amp;$x==strtr($y,$k)?$c:0);


Testcases

PHP >=7.1, 227 Bytes

prints 0 for false


[,$x,$y]=$argv;echo strlen($x)==strlen($y)?strtr($x,$c=array_filter(($f=array_flip)($z=$f(array_combine(($p=str_split)($x),$p($y)))),function($v,$k){return$k!=$v;},1))==$y&amp;$x==strtr($y,$z)?join(array_keys($c))." ".join($c):0:0;


Testcases

Expanded


[,$x,$y]=$argv; # 
echo strlen($x)==strlen($y) #compare string lengths
?strtr($x,  # replace function
$c=array_filter( # filter 
($f=array_flip)($z=$f( # # remove doubles like in testcase: a1 =&gt; 22
    array_combine(($p=str_split)($x),$p($y))  # replacement array keys string 1 values string 2 
))
    ,function($v,$k){return$k!=$v;},1)) # remove all keys that equal to values in array
    ==$y # boolean replacement string 1 equal to string 2
&amp;$x==strtr($y,$z) # boolean replacement string 2 equal to string 1        
?join(array_keys($c))." ".join($c) # output for true cases
    :0 # Output if replacement from string 1 is not equal to string 2
:0; #Output for different lengths