From 2b0ed8568b654397f16ef6d2a1372b1ebef1207a Mon Sep 17 00:00:00 2001 From: "Ch. Jnana Ramakrishna" <60878414+ph1nx@users.noreply.github.com> Date: Fri, 24 Jun 2022 09:44:27 -0400 Subject: [PATCH 1/3] Add files via upload --- RSA/RSA10.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ RSA/RSA9.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 RSA/RSA10.py create mode 100644 RSA/RSA9.py diff --git a/RSA/RSA10.py b/RSA/RSA10.py new file mode 100644 index 0000000..3db27e4 --- /dev/null +++ b/RSA/RSA10.py @@ -0,0 +1,44 @@ +from banner import * +from utils import * +banner() + +try: + import gmpy2 + from Crypto.Util.number import GCD + + c1 = int(input("==> c1 = ")) + c2 = int(input("==> c2 = ")) + e1 = int(input("==> e1 = ")) + e2 = int(input("==> e2 = ")) + n = int(input("==> n = ")) + """ + def common_modulus(c1, c2, e1, e2, n): + if GCD(e1, e2) != 1: + raise ValueError("Exponents e1 and e2 must be coprime") + t1 = int(modinv(e1,e2)) + t2 = int((GCD(e1,e2) - e1 * t1) / e2) + t3 = int(modinv(c2, n)) + m1 = pow(c1,t1,n) + m2 = pow(t3,-t2,n) + return (m1 * m2) % n + """ + def common_modulus(c1,c2,e1,e2,N): + g, s, t = gmpy2.gcdext(e1, e2) + assert e1 * s + e2 * t == 1 + if s < 0 and t > 0: + c1i = gmpy2.invert(c1, N) + m = (pow(c1i, -s, N) * pow(c2, t, N)) % N + elif s > 0 and t < 0: + c2i = gmpy2.invert(c2, N) + m = (pow(c1, s, N) * pow(c2i, -t, N)) % N + return m + Convert(common_modulus(c1, c2, e1, e2, n)) + +except ValueError: + slowprint("\n[-] c1, c2, e1, e2, n Must Be Integar Number") +except ImportError: + slowprint("\n[-] Module Not Setup") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() \ No newline at end of file diff --git a/RSA/RSA9.py b/RSA/RSA9.py new file mode 100644 index 0000000..d356948 --- /dev/null +++ b/RSA/RSA9.py @@ -0,0 +1,32 @@ +from banner import * +from utils import * +banner() + +try: + c1 = int(input("==> c1 = ")) + c2 = int(input("==> c2 = ")) + n1 = int(input("==> n1 = ")) + n2 = int(input("==> n2 = ")) + e = int(input("==> e = ")) + p = egcd(n1,n2)[0] + q1 = n1 // p + q2 = n2 // p + phi1 = (p - 1) * (q1 - 1) + phi2 = (p - 1) * (q2 - 1) + d1 = modinv(e,phi1) + d2 = modinv(e,phi2) + m1 = pow(c1,d1,n1) + Convert(m1) + m2 = pow(c2,d2,n2) + Convert(m2) +except TypeError: + slowprint("\n[-] No common factor for n1, n2") + exit() +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c1, c2, e, n1, n2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() From d001c2dd9f870f6d8b1d06c35d9a6d7313387512 Mon Sep 17 00:00:00 2001 From: "Ch. Jnana Ramakrishna" <60878414+ph1nx@users.noreply.github.com> Date: Fri, 24 Jun 2022 09:50:39 -0400 Subject: [PATCH 2/3] Added new attacks --- ZCrypt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ZCrypt.py b/ZCrypt.py index 4e300de..c53a2aa 100644 --- a/ZCrypt.py +++ b/ZCrypt.py @@ -33,10 +33,12 @@ [6] - (c,e) [Small Exponent("e") Attack] [7] - (c,p,q,dp,dq) [Chinese Remainder Theorem] [8] - (c,n,e) [Fermat Factorization] +[9] - (c1,c2,n1,n2,e) [Common Factor Attack] +[10] - (c1,c2,e1,e2,n) [Common Modulus Attack] [0] - Exit """) z = int(input("==> ")) - if int(z) >= 1 and int(z) <= 7: + if int(z) >= 1 and int(z) <= 10: os.system('tput reset') exec('import RSA.RSA'+str(z)) else: From baacdb455e928f19947be8940ed2700195d2c05e Mon Sep 17 00:00:00 2001 From: "Ch. Jnana Ramakrishna" <60878414+ph1nx@users.noreply.github.com> Date: Fri, 24 Jun 2022 09:54:05 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f244d6b..5c27d75 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ ZCrypt is a basic decryption tool for all CTF enthusiasts especially for Crypto- * (c,e) [Small Exponent("e") Attack] * (c,p,q,dp,dq) [Chinese Remainder Theorem] * (c,n,e) [Fermat Factorization] + * (c1,c2,n1,n2,e) [Common Factor Attack] + * (c1,c2,e1,e2,n) [Common Modulus Attack] #### XOR * Single Byte XOR