That’s is the actual reason you might need to rewrite it. If your critical system is written in an ancient script that nobody can understand, and does no longer supported, and as a security risk, at some point it will simply stop working. And there will be nobody that can fix it.
Yes, rewrite may be painful, but if you can no longer find the people to support the old thing it may be necessary