Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions RSA/RSA10.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions RSA/RSA9.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 3 additions & 1 deletion ZCrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down