Login
You're viewing the ruby.social public feed.
  • Nov 8, 2026, 8:08 PM
    @divVerent@vivaldi.net Not quite, but close:
    (p, q) = gen_rsa_key();
    n = p * q;
    vanity_n = hide_message(n);
    vanity_q = vanity_n / p;
    vanity_q = find_next_prime(vanity_q);
    return (p, vanity_q);
    
    If you already have one of the primes and want a particular public key, it's possible to calculate what the other "prime" by division. However, the resulting number is very unlikely to actually be a prime or even an integer.

    The trick is that since p and q have a similar size, incrementing q will only change the least-significant half of the modulus. Therefore, simply rounding to an integer and finding a nearby prime to the "ideal" q value will preserve a message hidden in the upper half of the modulus.
    💬 1🔄 0⭐ 9

Replies

  • Nov 8, 2026, 8:11 PM
    @divVerent@vivaldi.net My code does kinda "bruteforce" until (p-1)(q-1) doesn't share any factors with the public exponent, because that's a requirement for RSA... but it has always finished in one attempt so far.
    💬 1🔄 0⭐ 1
  • Nov 8, 2026, 8:31 PM

    @nothacking Yeah, you need that too, but it's basically irrelevant for security of your cert. Just important for it to work ;)

    💬 1🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • Nov 8, 2026, 10:41 PM
    @assimilateborg@kind.social @divVerent@vivaldi.net From what I've seen, LE will sign anything that doesn't have factors smaller than one thousand... but there's no way to actually use the resulting certificate without having the private exponent which is derived from the two primes.
    💬 0🔄 0⭐ 0
  • Nov 8, 2026, 8:31 PM

    @nothacking That method is probably somewhat worse than the method I described, but easier to implement.

    First of all, this makes q likely to be a prime after a large block of composites. Kinda biasing q. Not sure if there are known attacks for this property, but definitely a bias. Doesn't seem to be huge though, you maybe lost one bit of entropy there.

    Secondly, you basically ignored every other fun requirement RSA primes should have... but it seems like your primes _likely_ fulfill them, as p and q are unlikely - but possible - to become too close after your manipulation.

    💬 0🔄 0⭐ 1
  • Nov 8, 2026, 10:27 PM

    @divVerent @nothacking Any process for selecting a prime works this way. As numbers get large, primes get sparse, and you'll have large blocks of composites next to most.

    💬 0🔄 0⭐ 0