Would it be legal to publish a program to factor large semiprime numbers?
<p>If I somehow figured out a way to factor large semiprime numbers in a reasonable amount of time (don't worry, I haven't; this is hypothetical), would it be legal to publish the code?</p>
<p>This could be problematic because RSA, an encryption algorithm that Internet security is pretty much based on, can be trivially cracked by an attacker with the ability to factor the large semiprime numbers used. An attacker with such ability could quite easily have read and modified the contents of this page while it was being transferred to your browser if they controlled one of the routers the page passed through over the Internet.</p>

<h2>Sure</h2>
<p>But it’s been <a href="https://en.m.wikipedia.org/wiki/Shor%27s_algorithm" rel="noreferrer">done</a>. Admittedly, we don’t yet have the computer to run it for numbers bigger than 15 but the algorithm is ready to go.</p>

<p>Since you are asking about US law, the matter is very simple. See <a href="https://law.resource.org/pub/us/case/reporter/F3/176/176.F3d.1132.97-16686.html" rel="noreferrer">Bernstein v. US</a>, 176 F.3d 1132.</p>
<blockquote>
<p>The government defendants appeal the grant of summary judgment to the
plaintiff, Professor Daniel J. Bernstein (&quot;Bernstein&quot;), enjoining the
enforcement of certain Export Administration Regulations (&quot;EAR&quot;) that
limit Bernstein's ability to distribute encryption software. We find
that the EAR regulations (1) operate as a prepublication licensing
scheme that burdens scientific expression, (2) vest boundless
discretion in government officials, and (3) lack adequate procedural
safeguards. Consequently, we hold that <strong>the challenged regulations
constitute a prior restraint on speech that offends the First
Amendment</strong>. Although we employ a somewhat narrower rationale than did
the district court, its judgment is accordingly affirmed.</p>
</blockquote>
<p>It might remain <a href="https://en.wikipedia.org/wiki/Export_of_cryptography_from_the_United_States#U.S._export_rules" rel="noreferrer">illegal to export</a> some type of software, but it is not illegal to publish an algorithm.</p>

united-states software oregon hacking computer