To the extent code is functional rather than expressive it is not speech, and when the government seeks to compel code, it generally seeks to compel function not expressive content.
(That doesn’t mean it is not a bad idea, and even perhaps unconstitutional for other reasons.)
Code is speech, though, and is protected by the first amendment: see Bernstein v. United States.
I don't think a cryptographic algorithm is "expressive" any more than it is purely functional; indeed, the 9th circuit evaluated and rejected the expressive/functional distinction for source code in the above case.
Regardless - code is speech, and the government cannot compel or prevent speech except in very narrow circumstances.