RSA and Python

(xnacly.me)

11 points by ibobev3 days ago

4 comments

  • dfboyd33 minutes ago
    The way the article uses RSA is no better than a simple substitution cipher. Both the &quot;l&quot;s in &quot;hello&quot; are enciphered to 2575. It&#x27;s a newspaper cryptogram.<p>You&#x27;re supposed to concatenate all the input numbers, to create a message that has hundreds or thousands of digits; then RSA-encrypt that number.
  • nayuki25 minutes ago
    I have a different take on the same topic: <a href="https:&#x2F;&#x2F;www.nayuki.io&#x2F;page&#x2F;java-biginteger-was-made-for-rsa-cryptography" rel="nofollow">https:&#x2F;&#x2F;www.nayuki.io&#x2F;page&#x2F;java-biginteger-was-made-for-rsa-...</a><p>My article isn&#x27;t written as a step-by-step tutorial and doesn&#x27;t come with example numbers. But mine fills in certain things that xnacly doesn&#x27;t cover: random prime generation, efficiently calculating the decryption exponent d from (n, e) by using a modular inverse, using modular exponentiation instead of power-then-modulo.<p>By the way for Python, modular exponentiation is pow(x, y, m) (since 3.0), and modular inverse is pow(x, -1, m) (since 3.8, Oct 2019). <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functions.html#pow" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functions.html#pow</a>
  • gmiller12345651 minutes ago
    One of the bigger hurdles in implementing RSA is having an algorithm which can multiply the large numbers in real time. If you try a niave multiplication algorithm, you might find you&#x27;ll never get an answer. A lot of hardware now comes with special instructions which implement efficient algorithms for doing this.
    • MattPalmer108638 minutes ago
      Sure, you can&#x27;t use built in multiplication, but it isn&#x27;t a very big hurdle. Just use repeated squares, it&#x27;s fairly trivial to implement. I&#x27;ve worked on software that did this on very low power mobile payment devices.
      • SkiFire139 minutes ago
        Repeated squares is a way to implement exponentiation, not multiplication.
  • ashwinnair9952 minutes ago
    RSA is one of those algorithms where understanding it once actually sticks.