Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/rsa/bleichenbacher_signature_forgery.py
2589 views
1
def attack(suffix, suffix_bit_length):
2
"""
3
Returns a number s for which s^3 ends with the provided suffix.
4
:param suffix: the suffix
5
:param suffix_bit_length: the bit length of the suffix
6
:return: the number s
7
"""
8
assert suffix % 2 == 1, "Target suffix must be odd"
9
10
s = 1
11
for i in range(suffix_bit_length):
12
if (((s ** 3) >> i) & 1) != ((suffix >> i) & 1):
13
s |= (1 << i)
14
15
return s
16
17