Cracking the Enigma?
JavaScript, 40
(c,p)=&gt;c.search(p.replace(/./g,&quot;[^$&amp;]&quot;))

Using replace, this maps the plaintext input into a regular expression of form /[^H][^E][^L][^L][^O]/ (e.g., for plaintext input HELLO) and then uses search to test for the first index of the ciphertext substring that matches that regex. This regex means &quot;a pattern where the first character is not H, the second character is not E, etc.&quot;
$&amp; is a special sequence for replace output that substitutes in the value matched by the first replace argument (in this case, each single character matched by /./).