Finish challenge set 6, original challenges completed

This commit is contained in:
2023-02-05 17:42:58 -05:00
parent 1f2751a2f7
commit d81a8c3c30
5 changed files with 293 additions and 61 deletions

View File

@@ -2,11 +2,16 @@ import sys
from math import log, ceil, floor
from fractions import Fraction
# Case for which 2.b does not execute (Simple Case)
e = 3
d = 49245850836238243386848117224834103046337172957950760944544575720018018155267
n = 73868776254357365080272175837251154570062235041494422684546086388903725268033
# Case for which 2.b does execute (Complex Case)
e = 3
d = 7436226431632429054084263734954342197144411188982219770498201348078527629483
n = 11154339647448643581126395602431513296069677965376957820612905826953621832839
def bytes_needed(n: int) -> int:
if n == 0:
@@ -63,10 +68,6 @@ def test():
padded_m = 5300541194335152988749892502228755547482451611528547105226896651010982723
assert(padded_m == add_padding(m, k))
c_new = encrypt(padded_m)
c = 71554147358804792877798821486588152314859921438911236615156507964101619628630
assert(c == c_new)
assert(m == remove_padding(add_padding(m, k), k))
print('[tests passed]')
@@ -98,7 +99,9 @@ def main():
s += 1
elif len(m) > 1:
# Step 2.b: Searching with more than one interval left.
raise Exception("Not implemented")
s += 1
while not oracle(c * pow(s, e, n) % n):
s += 1
elif len(m) == 1:
# Step 2.c: Searching with one interval left.
a, b = m[0]
@@ -145,8 +148,7 @@ def main():
assert(m == 5300541194335152988749892502228755547482451611528547105226896651010982723)
m = remove_padding(m, k)
assert(m == m_orig)
print("[okay] Challenge 47: Bleichenbacher's PKCS 1.5 Padding Oracle (Simple Case)")
print("[okay] Challenge 48: Bleichenbacher's PKCS 1.5 Padding Oracle (Complex Case)")
main()