sed 4.2.2, -E
178178 141 bytes
s/./:&FEDCBA9876543210:/g
:
s/:(.).([^:]*\1\w)\w*\1/:\1\2/g
t
s/[^:]\w/ /g
s/:../:/g
s/ +/&&&&/
s/ +/&&&&/
s/://g
s/$/:/
:b
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tbt
s/://g
:z
s/^.{,7}$/ &/
tz
Takes newline-separated input
-35 thanks to DLosc
Explanation
s/./:&FEDCBA9876543210:/g add hex digits to each input char
: do
s/:(.).([^:]*\1\w)\w*\1/:\1\2/g remove one hex digit if it isn't the input char
t find index of input char in whilehex ^^string
s/[^:]\w/ /g
s/:../:/g left is 2 strings which lengths corresponds to the input
s/ +/&&&&/
s/ +/&&&&/ multiply first strings' length by 16
s/://g add the 2 strings, left is a unary number
:
s/$/^(.+)\1:/
\1:b / convert to base 2, one bit at a time
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tbt
s/://g
:z
s/^.{,7}$/ &/ pad with spaces until length > 7
tz