Skip to content

Instantly share code, notes, and snippets.

@paulsc
Created October 23, 2022 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsc/0ba2ad96842abc1d99b1156633430dc6 to your computer and use it in GitHub Desktop.
Save paulsc/0ba2ad96842abc1d99b1156633430dc6 to your computer and use it in GitHub Desktop.
while True:
get_context().precision = self.limit_precision(precision)
attempts += 1
testPrefix = prefix + urandom(self.keysize_bytes - len(prefix))
signatureCandidate = (
toBytes(
self.nthroot(
self.public_exponent,
toInt(testPrefix),
self.limit_precision(precision),
),
self.keysize_bytes,
)[: -len(signatureSuffix)]
+ signatureSuffix
)
sc = toInt(signatureCandidate)
p = pow(sc, self.public_exponent)
pbl = p.bit_length()
if pbl > self.keysize_bits:
self.report_small(pbl)
return None
toCheck = toBytes(p, (pbl + 7) // 8)
if 0 not in toCheck[: -len(signatureSuffix)]:
if progress:
if not self.quiet:
print("")
if attempts > 1:
if not self.quiet:
print("Found in", attempts, "attempt(s)")
return signatureCandidate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment