From 68b04a0643a5407234c2ea6a12de4b47e5b55f63 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 20 Dec 2018 19:10:39 +0200 Subject: [PATCH 001/122] Update RSA_wiener.py --- RSA_wiener.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/RSA_wiener.py b/RSA_wiener.py index 0d526ce..2c49a7a 100644 --- a/RSA_wiener.py +++ b/RSA_wiener.py @@ -77,7 +77,6 @@ def banner(): n = input(">>> n = ") e = input(">>> e = ") -c = input(">>> c = ") slowprint("\n[+] Please Wait ... \033[95m\n") @@ -130,8 +129,15 @@ def wiener(n, e): exit(0) d = wiener(n,e) -slowprint("[+] Getting PlainText ... \033[95m\n") -decode = pow(c,d,n) -output = (hex(decode)[2:].replace('L','')).decode("hex") -slowprint("[+] The PlainText = \033[95m") -print output +print "\nd = ",d +check = raw_input("\nYou Have Cipher [y/n] : ") +if check == "y" or check == "yes": + c = input(">>> c = ") + slowprint("[+] Getting PlainText ... \033[92m\n") + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = \033[92m") + print output +else : + slowprint("[+] Thanx For Using X-RSA \033[95m") + exit() From 5529a942330b5d18b0b31770fc11813f23b514f8 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Tue, 26 Feb 2019 19:35:46 +0200 Subject: [PATCH 002/122] Add files via upload --- factordb.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 factordb.py diff --git a/factordb.py b/factordb.py new file mode 100644 index 0000000..2109ea7 --- /dev/null +++ b/factordb.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function, unicode_literals +import requests + + +ENDPOINT = "http://factordb.com/api" + + +class FactorDB(): + def __init__(self, n): + self.n = n + self.result = None + + def connect(self, reconnect=False): + if self.result and not reconnect: + return self.result + self.result = requests.get(ENDPOINT, params={"query": str(self.n)}) + return self.result + + def get_id(self): + if self.result: + return self.result.json().get("id") + return None + + def get_status(self): + if self.result: + return self.result.json().get("status") + return None + + def get_factor_from_api(self): + if self.result: + return self.result.json().get("factors") + return None + + def get_factor_list(self): + """ + get_factors: [['2', 3], ['3', 2]] + Returns: [2, 2, 2, 3, 3] + """ + factors = self.get_factor_from_api() + if not factors: + return [] + ml = [[int(x)] * y for x, y in factors] + return [y for x in ml for y in x] From 773f973874bef3faf1e818c9b466de7b7f991757 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Tue, 26 Feb 2019 19:36:11 +0200 Subject: [PATCH 003/122] Update RSA.py --- RSA.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RSA.py b/RSA.py index efcec37..72ef2e6 100644 --- a/RSA.py +++ b/RSA.py @@ -74,6 +74,13 @@ def banner(): import binascii import gmpy2 +import requests +from factordb import * + +def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() @@ -107,7 +114,7 @@ def hex_pair(x): print(msg.decode()) else: slowprint("\n[+] Please Wait ... \033[95m\n") - factordb = RSA.attacks.factordb(n) + factordb = factordb(n) q = factordb[0] p = factordb[1] phi = (p-1)*(q-1) From 83c9abc27608217ce28a8d4f44d400298bfbc1f6 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 12:12:30 +0200 Subject: [PATCH 004/122] Update RSA_common_modulus.py --- RSA_common_modulus.py | 95 +++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py index 85653a5..4712f7f 100644 --- a/RSA_common_modulus.py +++ b/RSA_common_modulus.py @@ -65,56 +65,55 @@ def banner(): """ % (R, W,R)) banner() -c1 = input(">>> c1 = ") -c2 = input(">>> c2 = ") -e1 = input(">>> e1 = ") -e2 = input(">>> e2 = ") -n = input(">>> n = ") +try: + import gmpy2 + from Crypto.Util.number import * + c1 = int(raw_input(">>> c1 = ")) + c2 = int(raw_input(">>> c2 = ")) + e1 = int(raw_input(">>> e1 = ")) + e2 = int(raw_input(">>> e2 = ")) + n = int(raw_input(">>> n = ")) -slowprint("\n[+] Please Wait ... \033[95m\n") + slowprint("\n[+] Please Wait ... \033[95m\n") - -from sys import setrecursionlimit -import codecs -class Comod(object): - def accueil(self): - slowprint("[+] Getting info ... ") - setrecursionlimit(1000000) - def xgcd(self, a, b): - if a == 0: + def egcd(a, b): + if (a == 0): return (b, 0, 1) else: - gcd, u, v = self.xgcd(b % a, a) - return (gcd, v - (b // a) * u, u) - def modinv(self, a, n): - g, x, y = self.xgcd(a, n) - return x % n - def pow_mod(self, a, b, n): - number = 1 - while b: - if b & 1: - number = number * a % n - b >>= 1 - a = a * a % n - return number - def __init__(self, n, e1, e2, c1, c2): + g, y, x = egcd(b % a, a) + return (g, x - (b // a) * y, y) - self.accueil() - egcd = self.xgcd(e1, e2) - u, v = egcd[1], egcd[2] - if u >= 0: - p1 = self.pow_mod(c1,u,n) - else: - p1 = self.modinv(self.pow_mod(c1,-u,n),n) - if v >= 0: - p2 = self.pow_mod(c2,v,n) - else: - p2 = self.modinv(self.pow_mod(c2,(-v),n),n) - res = (p1 * p2) % n - print "\n\t[+] Decimal plaintext: ",res,"\n" - try: - plaintext = codecs.decode(hex(res)[2:].replace('L','')) - print "\t[+] The plaintext = ",plaintext - except: - slowprint("\t[-] Can't Get The PlainText\n") -Comod(n, e1, e2, c1, c2) + # Calculates a^{b} mod n when b is negative + def neg_pow(a, b, n): + assert b < 0 + assert GCD(a, n) == 1 + res = int(gmpy2.invert(a, n)) + res = pow(res, b*(-1), n) + return res + + + def common_modulus(e1, e2, n, c1, c2): + g, a, b = egcd(e1, e2) + if a < 0: + c1 = neg_pow(c1, a, n) + else: + c1 = pow(c1, a, n) + if b < 0: + c2 = neg_pow(c2, b, n) + else: + c2 = pow(c2, b, n) + ct = c1*c2 % n + m = int(gmpy2.iroot(ct, g)[0]) + return long_to_bytes(m) + slowprint("[+] The PlainText = ") + print common_modulus(e1, e2, n, c1, c2) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") From b4fad1cad681b12d239840ab4b4fda13a6cd262e Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 12:25:48 +0200 Subject: [PATCH 005/122] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acf781e..de6187b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ python Attack.py ``` # Screenshots : -![X-RSA](https://e.top4top.net/p_1073esqyv1.png "X-RSA in Action") +![X-RSA](https://f.top4top.net/p_1196js4bt1.png "X-RSA in Action") - Coded By X-Vector - [Facebook](https://www.facebook.com/X.Vector1) - [Linkedin](https://www.linkedin.com/in/x-vector/) - [Twitter](https://twitter.com/@XVector11) From db771930b34784e01b9ebdfd3a2d5aa7de3f8fb4 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 12:26:02 +0200 Subject: [PATCH 006/122] Delete Attack.py --- Attack.py | 144 ------------------------------------------------------ 1 file changed, 144 deletions(-) delete mode 100644 Attack.py diff --git a/Attack.py b/Attack.py deleted file mode 100644 index d82655a..0000000 --- a/Attack.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s + '\n': - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() - -print(""" -[1] - Attack(c,n,e) \033[92m -[2] - Attack(c,p,q,e) \033[96m -[3] - Attack (c,n,e,{p or q}) -[4] - Attack (c,n,e,dp) -[5] - Attack(c,n,d,e,phi) \033[93m -[6] - Attack(c1,c2,c3,n1,n2,n3) \033[95m [ Hasted ] -[7] - Attack(c1,c2,c3,n1,n2,n3,e) \033[0m [ Hasted2 ] -[8] - Attack(n,limit) \033[92m [ Fermat ] -[9] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] -[10] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] -[11] - Attack(n,e) \033[95m [ Wiener ] -[12] - Attack(c,n,d)\033[0m -[13] - Attack(c,d,n,e)\033[92m -[14] - Attack(c,n,e) \033[93m [ Multi Prime Number ] -[15] - Attack(c,e = 3)\033[0m -[16] - Get(n,p,q,d,e) From PublicKey\033[96m -[0] - Exit \033[92m - """) -x = int(input(">>> ")) -if x == 1: - os.system(clear) - import RSA -elif x == 2: - os.system(clear) - import RSA2 -elif x == 3: - os.system(clear) - import RSA6 -elif x == 4: - os.system(clear) - import RSA7 -elif x == 5: - os.system(clear) - import RSA3 -elif x == 6: - os.system(clear) - import RSA_hasted -elif x == 7: - os.system(clear) - import RSA_hasted2 -elif x == 8: - os.system(clear) - import RSA_fermat -elif x == 9: - os.system(clear) - import RSA_common_modulus -elif x == 10: - os.system(clear) - import RSA_chinese_remainder_theorem -elif x == 11: - os.system(clear) - import RSA_wiener -elif x == 12: - os.system(clear) - import RSA4 -elif x == 13: - os.system(clear) - import RSA5 -elif x == 14: - os.system(clear) - import RSA_multiPrime1 -elif x == 15: - os.system(clear) - import RSA8 -elif x == 16: - os.system(clear) - import public -else: - slowprint("\t\t\t[+] Thanx For using T00l <3") - exit() From 22280437decfc9797dbf01778f73a6928aea84e8 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 12:26:49 +0200 Subject: [PATCH 007/122] Add files via upload --- Attack.py | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Attack.py diff --git a/Attack.py b/Attack.py new file mode 100644 index 0000000..e9d8bd6 --- /dev/null +++ b/Attack.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python2 +#-*- coding: utf-8 -*- +# +# author : X-Vector +# Tested on Kali Linux / Parrot Os / Ubuntu +# Simple script for RSA Attack +import sys +import platform,os +from urllib2 import * +from platform import system +def slowprint(s): + for c in s + '\n': + sys.stdout.write(c) + sys.stdout.flush() + time.sleep(4. / 100) + +clear = "" +if "Windows" in platform.system(): + clear = "cls" +if "Linux" in platform.system(): + clear = "clear" +os.system(clear) +is_windows = sys.platform.startswith('win') + +# Console Colors +if is_windows: + # Windows deserves coloring too :D + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + try: + import win_unicode_console , colorama + win_unicode_console.enable() + colorama.init() + #Now the unicode will work ^_^ + except: + print("[!] Error: Coloring libraries not installed, no coloring will be used") + G = Y = B = R = W = G = Y = B = R = W = '' + + +else: + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + + +def banner(): + print("""%s + +_____ ________________ _____ _____ +\ \ / /\ \ _____\ \ / |_ + \ | | / \ /\ \ / / \ | / \\ + \ \ / / | \_\ | | | /___/|| /\ \\ + \ | / | ___/ ____\ \ | ||| | | \\ + / | \ | \ ____ / /\ \|___|/| \/ \\ + / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ + |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ + | | | | | | | | || | || | | | | | | | + |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| + %s%s +[ Version : 0.2 ]\033[92m +[ Author : X-Vector ]\033[96m +[ Github : github.com/X-Vector ]\033[93m +[ Twitter : twitter.com/@XVector11 ]\033[95m +[ Facebook: facebook.com/X.Vector1 ]\033[95m +[ GreeteZ : Karem Ali ]\033[94m + """ % (R, W,R)) +banner() + +print(""" +[1] - Attack(c,n,e) \033[92m +[2] - Attack(c,p,q,e) \033[96m +[3] - Attack (c,n,e,{p or q}) +[4] - Attack (c,n,e,dp) +[5] - Attack(c,n,d,e,phi) \033[93m +[6] - Attack(c1,c2,c3,n1,n2,n3) \033[95m [ Hasted ] +[7] - Attack(c1,c2,c3,n1,n2,n3,e) \033[0m [ Hasted2 ] +[8] - Attack(n,limit) \033[92m [ Fermat ] +[9] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] +[10] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] +[11] - Attack(n,e) \033[95m [ Wiener ] +[12] - Attack(c,n,d)\033[0m +[13] - Attack(c,d,n,e)\033[92m +[14] - Attack(c,n,e) \033[93m [ Multi Prime Number ] +[15] - Attack(c,e = 3)\033[0m +[0] - Exit \033[92m + """) +x = int(input(">>> ")) +if x == 1: + os.system(clear) + import RSA +elif x == 2: + os.system(clear) + import RSA2 +elif x == 3: + os.system(clear) + import RSA6 +elif x == 4: + os.system(clear) + import RSA7 +elif x == 5: + os.system(clear) + import RSA3 +elif x == 6: + os.system(clear) + import RSA_hasted +elif x == 7: + os.system(clear) + import RSA_hasted2 +elif x == 8: + os.system(clear) + import RSA_fermat +elif x == 9: + os.system(clear) + import RSA_common_modulus +elif x == 10: + os.system(clear) + import RSA_chinese_remainder_theorem +elif x == 11: + os.system(clear) + import RSA_wiener +elif x == 12: + os.system(clear) + import RSA4 +elif x == 13: + os.system(clear) + import RSA5 +elif x == 14: + os.system(clear) + import RSA_multiPrime1 +elif x == 15: + os.system(clear) + import RSA8 +else: + slowprint("\t\t\t[+] Thanx For using T00l <3") + exit() From d393d1da6c3b1bd1a9da1be39a00b945913836ea Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 12:27:00 +0200 Subject: [PATCH 008/122] Delete public.py --- public.py | 152 ------------------------------------------------------ 1 file changed, 152 deletions(-) delete mode 100644 public.py diff --git a/public.py b/public.py deleted file mode 100644 index b51e2d7..0000000 --- a/public.py +++ /dev/null @@ -1,152 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.1 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - -import argparse -from Crypto.PublicKey import RSA - -k = raw_input("Enter Path of Public Key : ") -try: - key=RSA.importKey(open(k, 'r').read()) - slowprint("[+] Please Wait ... ") - n = key.n - e = key.e - - from CryptoLib.RSA import RSA - import binascii - - - factordb = RSA.attacks.factordb(n) - q = factordb[0] - p = factordb[1] - - slowprint("[+] Getting n,p,q,d,e ... ") - - - print("\n[+] n = {}".format(str(n))) - print("\n[+] e = {}".format(str(e))) - print("\n[+] p = {}".format(str(p))) - print("\n[+] q = {}".format(str(q))) - - import random - import Crypto.PublicKey.RSA - class Wiener(object): - def accueil(self): - slowprint("") - - def division_euclidienne(self, a, b): - return (a // b, a % b) - def fraction_continue(self, n, d): - developpement = [] - a = n - b = d - while b != 0: - (q,r) = self.division_euclidienne(a,b) - developpement.append(q) - a = b - b = r - return (developpement) - def reduites_fraction_continue(self, a): - l=len(a) - reduites=[] - h0 = 1 - h1 = 0 - k0 = 0 - k1 = 1 - count = 0 - while count < l: - h = a[count] * h1 + h0 - h0 = h1 - h1 = h - k = a[count] * k1 + k0 - k0 = k1 - k1 = k - reduites.append((k,h)) - count += 1 - return (reduites) - def wiener(self, n, e): - fc = self.fraction_continue(e, n) - reduites = self.reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - return (reduites[i][1]) - else: - print("\t[-] This RSA public key isn't a valid candidate to a Wiener Attack\n") - exit(0) - def __init__(self, n, e): - self.accueil() - self.d = self.wiener(n, e) - print ("[+] d = {}".format(self.d)) - Wiener(n,e) - slowprint("\n[+] Thanx For Using X-RSA Tool <3 \033[95m\n") -except: - slowprint("[-] False Attack !! ") From 097c4e46e8baec750b3f1bd9fe154ea7e02d8edf Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:56:52 +0200 Subject: [PATCH 009/122] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de6187b..b42cad4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ python Attack.py ``` # Screenshots : -![X-RSA](https://f.top4top.net/p_1196js4bt1.png "X-RSA in Action") +![X-RSA](https://e.top4top.net/p_1196pglz71.png "X-RSA in Action") - Coded By X-Vector - [Facebook](https://www.facebook.com/X.Vector1) - [Linkedin](https://www.linkedin.com/in/x-vector/) - [Twitter](https://twitter.com/@XVector11) From 7c2b0551715c82d7a4cad02aec385d7774c225e2 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:57:38 +0200 Subject: [PATCH 010/122] Delete RSA_hasted2.py --- RSA_hasted2.py | 131 ------------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 RSA_hasted2.py diff --git a/RSA_hasted2.py b/RSA_hasted2.py deleted file mode 100644 index e2a9fd2..0000000 --- a/RSA_hasted2.py +++ /dev/null @@ -1,131 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - - -#Example -""" -N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 -C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 -N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 -C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 -N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 -C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 -e = 3 -""" -C1 = input(">>> c1 = ") -C2 = input(">>> c2 = ") -C3 = input(">>> c3 = ") -N1 = input(">>> n1 = ") -N2 = input(">>> n2 = ") -N3 = input(">>> n3 = ") -e = input(">>> e = ") - -slowprint("\n[+] Please Wait ... \033[95m\n") - -try: - def mulinv(a,b): - b0 = b - x0, x1 = 0, 1 - if b == 1: return 1 - while a > 1: - q = a / b - a, b = b, a%b - x0, x1 = x1 - q * x0, x0 - if x1 < 0: x1 += b0 - return x1 - def powinv(x,n): - high = 1 - while high ** n < x: - high *= 2 - low = high/2 - while low < high: - mid = (low + high) // 2 - if low < mid and mid**n < x: - low = mid - elif high > mid and mid**n > x: - high = mid - else: - return mid - return mid + 1 - - def hasted(n1,n2,n3,chipher_text_1,chipher_text_2,chipher_text_3,e): - n = [n1,n2,n3] - a = [chipher_text_1,chipher_text_2,chipher_text_3] - sum = 0 - prod = reduce(lambda a, b: a*b, n) - for n_i, a_i in zip(n, a): - p = prod / n_i - sum += a_i * mulinv(p, n_i) * p - return powinv(sum % p,e) - - decode = (hex(hasted(N1,N2,N3,C1,C2,C3,e))[2:]).replace('L','') - slowprint("[+] The PlainText = ") - print decode.decode("hex") - slowprint("[+] Thanx For Using X-RSA Tool <3 \033[95m\n") -except: - slowprint("[-] False Attack !! \n") From a9122cdb17f30772c01dfbe7ba49cea7e97a2cef Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:58:27 +0200 Subject: [PATCH 011/122] Update Attack.py --- Attack.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Attack.py b/Attack.py index e9d8bd6..1335641 100644 --- a/Attack.py +++ b/Attack.py @@ -77,16 +77,15 @@ def banner(): [3] - Attack (c,n,e,{p or q}) [4] - Attack (c,n,e,dp) [5] - Attack(c,n,d,e,phi) \033[93m -[6] - Attack(c1,c2,c3,n1,n2,n3) \033[95m [ Hasted ] -[7] - Attack(c1,c2,c3,n1,n2,n3,e) \033[0m [ Hasted2 ] -[8] - Attack(n,limit) \033[92m [ Fermat ] -[9] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] -[10] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] -[11] - Attack(n,e) \033[95m [ Wiener ] -[12] - Attack(c,n,d)\033[0m -[13] - Attack(c,d,n,e)\033[92m -[14] - Attack(c,n,e) \033[93m [ Multi Prime Number ] -[15] - Attack(c,e = 3)\033[0m +[6] - Attack(c1,c2,c3,n1,n2,n3,e=3) \033[95m [ Hasted ] +[7] - Attack(n,limit) \033[92m [ Fermat ] +[8] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] +[9] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] +[10] - Attack(n,e) \033[95m [ Wiener ] +[11] - Attack(c,n,d)\033[0m +[12] - Attack(c,d,n,e)\033[92m +[13] - Attack(c,n,e) \033[93m [ Multi Prime Number ] +[14] - Attack(c,e = 3)\033[0m [0] - Exit \033[92m """) x = int(input(">>> ")) @@ -109,30 +108,27 @@ def banner(): os.system(clear) import RSA_hasted elif x == 7: - os.system(clear) - import RSA_hasted2 -elif x == 8: os.system(clear) import RSA_fermat -elif x == 9: +elif x == 8: os.system(clear) import RSA_common_modulus -elif x == 10: +elif x == 9: os.system(clear) import RSA_chinese_remainder_theorem -elif x == 11: +elif x == 10: os.system(clear) import RSA_wiener -elif x == 12: +elif x == 11: os.system(clear) import RSA4 -elif x == 13: +elif x == 12: os.system(clear) import RSA5 -elif x == 14: +elif x == 13: os.system(clear) import RSA_multiPrime1 -elif x == 15: +elif x == 14: os.system(clear) import RSA8 else: From ca19f3bc6b8e75cff76c9e8a8bc21aa5e3330730 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:58:40 +0200 Subject: [PATCH 012/122] Update RSA.py --- RSA.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/RSA.py b/RSA.py index 72ef2e6..78fd234 100644 --- a/RSA.py +++ b/RSA.py @@ -50,7 +50,6 @@ def slowprint(s): def banner(): print("""%s - _____ ________________ _____ _____ \ \ / /\ \ _____\ \ / |_ \ | | / \ /\ \ / / \ | / \\ @@ -68,22 +67,9 @@ def banner(): [ Twitter : twitter.com/@XVector11 ]\033[95m [ Facebook: facebook.com/X.Vector1 ]\033[95m [ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) banner() -import binascii -import gmpy2 -import requests -from factordb import * - -def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - - - # Example 1 : #c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 #n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 @@ -94,15 +80,22 @@ def factordb(n): #e = 3 #c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 - -c = input(">>> c = ") -n = input(">>> n = ") -e = input(">>> e = ") - - -gmpy2.get_context().precision=200 -m = gmpy2.iroot(c, e)[0] try: + import binascii + import gmpy2 + import requests + from factordb import * + + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + gmpy2.get_context().precision=200 + m = gmpy2.iroot(c, e)[0] + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) if pow(m,e) == c: slowprint("\n[+] Please Wait ... \033[95m\n") def hex_pair(x): @@ -141,5 +134,13 @@ def modinv(a,m): except IndexError: slowprint("[-] Sorry Can't Factorize n :( ") slowprint("\n[!] Try To Use MultiPrime Attack ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From ae623da608496f664d6659e7e994675b058d19f3 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:59:03 +0200 Subject: [PATCH 013/122] Update RSA2.py --- RSA2.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/RSA2.py b/RSA2.py index b82d75c..74273da 100644 --- a/RSA2.py +++ b/RSA2.py @@ -1,4 +1,3 @@ -# p , q , e , c is required import sys import platform,os from urllib2 import * @@ -67,7 +66,6 @@ def banner(): """ % (R, W,R)) banner() -import gmpy #c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 @@ -75,12 +73,14 @@ def banner(): #q = 296805874594538235115008173244022912163 #e = 3 -c = input(">>> c = ") -p = input(">>> p = ") -q = input(">>> q = ") -e = input(">>> e = ") -slowprint("\n[+] Please Wait ... \033[95m\n") + try: + import gmpy + c = int(raw_input(">>> c = ")) + p = int(raw_input(">>> p = ")) + q = int(raw_input(">>> q = ")) + e = int(raw_input(">>> e = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") n = p*q x = (p-1)*(q-1) d = gmpy.invert(e,x) @@ -89,5 +89,13 @@ def banner(): slowprint("[+] The PlainText = ") print(decode) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From da57b625a0170b201ca7ae66139c3c8430d0d2bb Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:59:17 +0200 Subject: [PATCH 014/122] Update RSA3.py --- RSA3.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/RSA3.py b/RSA3.py index b4abc50..23a766f 100644 --- a/RSA3.py +++ b/RSA3.py @@ -73,18 +73,23 @@ def banner(): #e = 65537 #phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 -c = input(">>> c = ") -n = input(">>> n = ") -d = input(">>> d = ") -e = input(">>> e = ") -phi = input(">>> phi = ") - try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + d = int(raw_input(">>> d = ")) + e = int(raw_input(">>> e = ")) + phi = int(raw_input(">>> phi = ")) slowprint("\n[+] Please Wait ... \033[95m\n") n = hex(pow(c,d,n))[2:] decode = (n.replace('L','')).decode("hex") slowprint("[+] The PlainText = ") print decode +except ValueError: + slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("\n[!] False Attack ... \033[95m\n") + slowprint("\n[-] False Attack !") From 18b256a64622c03f15c5ca93e2d2076350066921 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:59:30 +0200 Subject: [PATCH 015/122] Update RSA4.py --- RSA4.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/RSA4.py b/RSA4.py index cac2b5f..5e0f804 100644 --- a/RSA4.py +++ b/RSA4.py @@ -70,15 +70,23 @@ def banner(): #d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 #c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 -c = input(">>> c = ") -n = input(">>> n = ") -d = input(">>> d = ") -slowprint("\n[+] Please Wait ... \033[95m\n") + + try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + d = int(raw_input(">>> d = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") decode = pow(c,d,n) output = (hex(decode)[2:].replace('L','')).decode("hex") slowprint("[+] The PlainText = ") print output +except ValueError: + slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From 52f849b210573e1ac1f6b6fe8ef423955de479f5 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:59:41 +0200 Subject: [PATCH 016/122] Update RSA5.py --- RSA5.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/RSA5.py b/RSA5.py index 0b32086..9e7ad17 100644 --- a/RSA5.py +++ b/RSA5.py @@ -70,22 +70,18 @@ def banner(): [ GreeteZ : Karem Ali ]\033[94m """ % (R, W,R)) banner() - -from Crypto.PublicKey import RSA -import sympy as sp -import math +try: + from Crypto.PublicKey import RSA + import sympy as sp + import math +except ImportError: + slowprint("\n[-] Module Not Setup") """ #n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 #e = 65537 #d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 #c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 """ -n = input(">>> n = ") -e = input(">>> e = ") -d = input(">>> d = ") -c = input(">>> c = ") - -slowprint("\n[+] Please Wait ... \033[95m\n") def premRSA(n,e,d,c): bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) @@ -131,9 +127,6 @@ def extended_gcd(aa, bb): return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) def modinv(a, m): - """Modular Multiplicative Inverse, - from https://rosettacode.org/wiki/Modular_inverse#Python - """ g, x, y = extended_gcd(a, m) if g != 1: raise ValueError @@ -151,6 +144,18 @@ def floorSqrt(n): try: + slowprint("\n[+] Please Wait ... \033[95m\n") + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + d = int(raw_input(">>> d = ")) premRSA(n,e,d,c) + +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("\n[!] False Attack ... \033[95m\n") + slowprint("\n[-] False Attack !") From 70692f5310843244a732fb17c255d9bc87712185 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 16:59:53 +0200 Subject: [PATCH 017/122] Update RSA6.py --- RSA6.py | 60 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/RSA6.py b/RSA6.py index 068fd93..ff46496 100644 --- a/RSA6.py +++ b/RSA6.py @@ -79,31 +79,37 @@ def banner(): e = 65537 n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 """ -c = input(">>> c = ") -n = input(">>> n = ") -e = input(">>> e = ") -p = input(">>> p or q = ") +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + p = int(raw_input(">>> p = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + q = n/p + phi = (p-1)*(q-1) + def egcd(a,b): + if a == 0 : + return(b,0,1) + else: + g,y,x = egcd(b%a,a) + return (g,x-(b/a)*y,y) + def modinv(a,m): + g,x,y = egcd(a,m) + if g != 1: + raise Expection("RSA Hello") + else : + return x%m + d = modinv(e,phi) + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print(output) - -slowprint("\n[+] Please Wait ... \033[95m\n") - -q = n/p -phi = (p-1)*(q-1) -def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) -def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("RSA Hello") - else : - return x%m - -d = modinv(e,phi) -decode = pow(c,d,n) -output = (hex(decode)[2:].replace('L','')).decode("hex") -slowprint("[+] The PlainText = ") -print(output) +except ValueError: + slowprint("\n[-] c,n,e,p Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") From f2d9c2aacd4adf90caf6b1cecc9def3b7b90af98 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:00:06 +0200 Subject: [PATCH 018/122] Update RSA7.py --- RSA7.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/RSA7.py b/RSA7.py index 9ededd1..a0f4478 100644 --- a/RSA7.py +++ b/RSA7.py @@ -78,22 +78,20 @@ def banner(): dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 """ -c = input(">>> c = ") -n = input(">>> n = ") -e = input(">>> e = ") -dp = input(">>> dp = ") -# dP = (1/e) mod (p-1) -mp = (dp * e) - 1 #mp is multiple of p-1 -for i in range(2,1000000): - p = (mp / i) + 1 - if n % p == 0: - break -#print "p = ",p -q = n/p -#print "q = ",q -slowprint("\n[+] Please Wait ... \033[95m\n") try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + dp = int(raw_input(">>> dp = ")) + + mp = (dp * e) - 1 + for i in range(2,1000000): + p = (mp / i) + 1 + if n % p == 0: + break + q = n/p + slowprint("\n[+] Please Wait ... \033[95m\n") phi = (p-1)*(q-1) def egcd(a,b): if a == 0 : @@ -113,5 +111,12 @@ def modinv(a,m): output = (hex(decode)[2:].replace('L','')).decode("hex") slowprint("[+] The PlainText = ") print(output) + +except ValueError: + slowprint("\n[-] c,n,e,p Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From 2728778644a9e3418682581e2ce6f32b7277f0a5 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:00:20 +0200 Subject: [PATCH 019/122] Update RSA8.py --- RSA8.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/RSA8.py b/RSA8.py index 138bd3b..5966afc 100644 --- a/RSA8.py +++ b/RSA8.py @@ -65,16 +65,17 @@ def banner(): """ % (R, W,R)) banner() -import gmpy2 -import binascii -gmpy2.get_context().precision=99999999999999999 # Example #c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 -c = input(">>> c = ") -slowprint("\n[+] Please Wait ... \033[95m\n") + try: + import gmpy2 + import binascii + gmpy2.get_context().precision=99999999999999999 + c = int(raw_input(">>> c = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") m = gmpy2.iroot(c, 3)[0] assert pow(m,3) == c def hex_pair(x): @@ -84,5 +85,13 @@ def hex_pair(x): msg = binascii.unhexlify(m_hex) slowprint("[+] The PlainText = ") print(msg.decode()) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From 42b60e0f8c1b846643c6692764f838f409cde8ca Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:00:34 +0200 Subject: [PATCH 020/122] Update RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py index a465dc9..180fc98 100644 --- a/RSA_chinese_remainder_theorem.py +++ b/RSA_chinese_remainder_theorem.py @@ -75,15 +75,17 @@ def banner(): dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 """ -c = input(">>> c = ") -p = input(">>> p = ") -q = input(">>> q = ") -dp = input(">>> dp = ") -dq = input(">>> dq = ") -slowprint("\n[+] Please Wait ... \033[95m\n") + try: + c = int(raw_input(">>> c = ")) + p = int(raw_input(">>> p = ")) + q = int(raw_input(">>> q = ")) + dp = int(raw_input(">>> dp = ")) + dp = int(raw_input(">>> dq = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + def egcd(a,b): if a == 0: return (b, 0, 1) @@ -105,5 +107,11 @@ def chinese_remainder_theorem(p,q,dp,dq,chipher_text): decode = hex(chinese_remainder_theorem(p,q,dp,dq,c))[2:].replace('L','') slowprint("[+] The PlainText = ") print decode.decode("hex") +except ValueError: + slowprint("\n[-] c,n,e,p Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() except: - slowprint("[-] False Attack !! \n") + slowprint("\n[-] False Attack !") From 8b6cc5f6adcbe4bce6513069e1da2cc7134870ab Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:01:27 +0200 Subject: [PATCH 021/122] Update RSA_fermat.py --- RSA_fermat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RSA_fermat.py b/RSA_fermat.py index 02309e0..ac849c4 100644 --- a/RSA_fermat.py +++ b/RSA_fermat.py @@ -66,8 +66,8 @@ def banner(): """ % (R, W,R)) banner() -n = input(">>> n = ") -limit = input(">>> limit = ") +n = int(raw_input(">>> n = ")) +limit = int(raw_input(">>> limit = ")) slowprint("\n[+] Please Wait ... \033[95m\n") From c5dd000467dfbc288a1a7054aa6defe8a337198a Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:01:45 +0200 Subject: [PATCH 022/122] Update RSA_hasted.py --- RSA_hasted.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/RSA_hasted.py b/RSA_hasted.py index a19fd37..329f876 100644 --- a/RSA_hasted.py +++ b/RSA_hasted.py @@ -76,18 +76,6 @@ def banner(): # C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 -C1 = input(">>> c1 = ") -C2 = input(">>> c2 = ") -C3 = input(">>> c3 = ") -N1 = input(">>> n1 = ") -N2 = input(">>> n2 = ") -N3 = input(">>> n3 = ") - - -slowprint("\n[+] Please Wait ... \033[95m\n") - -import functools -import itertools def chinese_remainder(n, a): sum = 0 @@ -122,10 +110,23 @@ def inv_pow(c, e): assert pow(m, e) == c return m -N = [N1, N2, N3] -C = [C1, C2, C3] -e = len(N) + try: + import functools + import itertools + + C1 = int(raw_input(">>> c1 = ")) + C2 = int(raw_input(">>> c2 = ")) + C3 = int(raw_input(">>> c3 = ")) + N1 = int(raw_input(">>> n1 = ")) + N2 = int(raw_input(">>> n2 = ")) + N3 = int(raw_input(">>> n3 = ")) + N = [N1, N2, N3] + C = [C1, C2, C3] + e = len(N) + print "e = ",e + slowprint("\n[+] Please Wait ... \033[95m\n") + a = chinese_remainder(N, C) for n, c in zip(N, C): assert a % n == c @@ -133,6 +134,13 @@ def inv_pow(c, e): decode = (hex(m)[2:]).replace('L','') slowprint("[+] The PlainText = ") print decode.decode("hex") - slowprint("\n[+] Thanx For Using X-RSA Tool <3 \033[95m\n") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except ImportError: + slowprint("\n[-] Module Not Setup") except: - slowprint("[-] False Attack !! ") + slowprint("\n[-] False Attack !") From 544a5a62113a3b63ba55a96d6893987b5dbae38a Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:01:58 +0200 Subject: [PATCH 023/122] Update RSA_multiPrime1.py --- RSA_multiPrime1.py | 132 ++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 75 deletions(-) diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py index fb584a9..282ef95 100644 --- a/RSA_multiPrime1.py +++ b/RSA_multiPrime1.py @@ -44,7 +44,6 @@ def slowprint(s): def banner(): print("""%s - _____ ________________ _____ _____ \ \ / /\ \ _____\ \ / |_ \ | | / \ /\ \ / / \ | / \\ @@ -62,80 +61,63 @@ def banner(): [ Twitter : twitter.com/@XVector11 ]\033[95m [ Facebook: facebook.com/X.Vector1 ]\033[95m [ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) banner() - -from Crypto.PublicKey import RSA -from Crypto.Util import asn1 -import binascii -primes = [] -def prime_factors(n): - i = 2 - while i * i <= n: - if n % i: - i += 1 - else: - n //= i - primes.append(i) - if n > 1: - primes.append(n) - return primes - - -c = input(">>> c = ") -n = input(">>> n = ") -e = input(">>> e = ") - -#https://www.alpertron.com.ar/ECM.HTM - -#Example - -#e=65537 -#c=948626122185577940383278469624490186926710623520188126435501983438183336907186255794618530332289368021291789118954846772779855308711280972165698348170051078399678590370050111906031923460860172422708816752545784573579942145045344015318568999211937934532123400243017531300488990627956390410869348218289952 -#primes = [2162771687,2180377501,2181902579,2183410837,2234829049,2259158687,2366491411,2494545509,2528730847,2591025083,2603976511,2691605771,2714412037,2808388853,2847171653,2870886637,2890555183,2939087189,3000625669,3175105811,3226441579,3265841311,3499273711,3544821197,3611944027,3677851391,3692380933,3696854989,4067996287,4133178029,4212919157,4224110131] - -os.system(clear) -banner() - -print("[!!] Ok , Now :\n1 - You Can Factorize (n) Auto With X-RSA \t[ it Take Much Time ]\n2 - You Can Factorize (n) in This Site https://www.alpertron.com.ar/ECM.HTM \t [ Recommend ]\n") -check = int(input(">>> ")) -if check == 1: - slowprint("\n[+] Please Wait ... \033[95m") - slowprint("\n[+] it Take Much Time ... \033[95m\n") - prime_factors(n) -elif check == 2: - slowprint("\n[+] How Many Prime Number = \033[95m\n") - count = int(input(">>> ")) - print "\n" - for i in range(count): - print "Enter The",(i+1),"Number" - i = int(input(">>> ")) - primes.append(i) - -phi = 1 -for prime in primes: - phi *= (prime-1) - - -def egcd(a, b): - if a == 0: - return (b, 0, 1) - g, y, x = egcd(b%a,a) - return (g, x - (b//a) * y, y) - -def modinv(a, m): - g, x, y = egcd(a, m) - if g != 1: - raise Exception('No modular inverse') - return x%m -d = modinv(e, phi) -m = pow(c, d, n) -def hex_pair(x): - return ('0' * (len(x) % 2)) + x -m_hex = '{:x}'.format(m) -m_hex = hex_pair(m_hex) -msg = binascii.unhexlify(m_hex) -slowprint("\n[+] The PlainText = ") -print(msg.decode(errors="ignore")) +""" +c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 +n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 +e= 65537 +prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] +""" + +try: + from factordb import * + import binascii + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + prime = [] + for i in factordb(n): + prime.append(i) + phi = 1 + for i in prime: + phi *= i-1 + def egcd(a, b): + if a == 0: + return (b, 0, 1) + g, y, x = egcd(b%a,a) + return (g, x - (b//a) * y, y) + def modinv(a, m): + g, x, y = egcd(a, m) + if g != 1: + raise Exception('No modular inverse') + return x%m + d = modinv(e, phi) + m = pow(c, d, n) + def hex_pair(x): + return ('0' * (len(x) % 2)) + x + m_hex = '{:x}'.format(m) + m_hex = hex_pair(m_hex) + msg = binascii.unhexlify(m_hex) + slowprint("\n[+] The PlainText = ") + print(msg.decode(errors="ignore")) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,n,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except Exception: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("[-] False Attack !") From 7304c91334aa152515019971726ccbe63dab3e50 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Thu, 11 Apr 2019 17:02:09 +0200 Subject: [PATCH 024/122] Update RSA_wiener.py --- RSA_wiener.py | 144 +++++++++++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/RSA_wiener.py b/RSA_wiener.py index 2c49a7a..d2d4c80 100644 --- a/RSA_wiener.py +++ b/RSA_wiener.py @@ -74,70 +74,82 @@ def banner(): c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 """ - -n = input(">>> n = ") -e = input(">>> e = ") - -slowprint("\n[+] Please Wait ... \033[95m\n") - -import random - -def division_euclidienne(a, b): - return (a // b, a % b) -def fraction_continue(n, d): - developpement = [] - a = n - b = d - while b != 0: - (q,r) = division_euclidienne(a,b) - developpement.append(q) - a = b - b = r - return (developpement) -def reduites_fraction_continue(a): - l=len(a) - reduites=[] - h0 = 1 - h1 = 0 - k0 = 0 - k1 = 1 - count = 0 - while count < l: - h = a[count] * h1 + h0 - h0 = h1 - h1 = h - k = a[count] * k1 + k0 - k0 = k1 - k1 = k - reduites.append((k,h)) - count += 1 - return (reduites) -def wiener(n, e): - fc = fraction_continue(e, n) - reduites = reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - slowprint("[+] Getting d ... \033[95m\n") - return (reduites[i][1]) - else: - print("[-] Sorry it's Not Wiener Attack\n") - exit(0) - -d = wiener(n,e) -print "\nd = ",d -check = raw_input("\nYou Have Cipher [y/n] : ") -if check == "y" or check == "yes": - c = input(">>> c = ") - slowprint("[+] Getting PlainText ... \033[92m\n") - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = \033[92m") - print output -else : - slowprint("[+] Thanx For Using X-RSA \033[95m") +try: + import random + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + + slowprint("\n[+] Please Wait ... \033[95m\n") + + def division_euclidienne(a, b): + return (a // b, a % b) + def fraction_continue(n, d): + developpement = [] + a = n + b = d + while b != 0: + (q,r) = division_euclidienne(a,b) + developpement.append(q) + a = b + b = r + return (developpement) + def reduites_fraction_continue(a): + l=len(a) + reduites=[] + h0 = 1 + h1 = 0 + k0 = 0 + k1 = 1 + count = 0 + while count < l: + h = a[count] * h1 + h0 + h0 = h1 + h1 = h + k = a[count] * k1 + k0 + k0 = k1 + k1 = k + reduites.append((k,h)) + count += 1 + return (reduites) + def wiener(n, e): + fc = fraction_continue(e, n) + reduites = reduites_fraction_continue(fc) + message_clair = random.randint(10**1,10**5) + message_chiffre = pow(message_clair, e, n) + l = len(reduites) + i = 0 + while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: + i += 1 + if i != l: + slowprint("[+] Getting d ... \033[95m\n") + return (reduites[i][1]) + else: + print("[-] Sorry it's Not Wiener Attack\n") + exit(0) + + d = wiener(n,e) + print "\nd = ",d + check = raw_input("\nYou Have Cipher [y/n] : ") + if check == "y" or check == "yes": + c = int(raw_input(">>> c = ")) + slowprint("[+] Getting PlainText ... \033[92m\n") + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = \033[92m") + print output + else : + slowprint("[+] Thanx For Using X-RSA \033[95m") + exit() + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: exit() +except Exception: + slowprint("\n[-] Wrong Data") +except: + slowprint("\n[-] False Attack !") From 6db395289a9174b781828341c9d6ec57edd440cf Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Fri, 12 Apr 2019 16:27:26 +0200 Subject: [PATCH 025/122] Update RSA_multiPrime1.py --- RSA_multiPrime1.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py index 282ef95..bd0c44a 100644 --- a/RSA_multiPrime1.py +++ b/RSA_multiPrime1.py @@ -72,18 +72,13 @@ def banner(): """ try: - from factordb import * + from fator_multi_prime import * import binascii c = int(raw_input(">>> c = ")) n = int(raw_input(">>> n = ")) e = int(raw_input(">>> e = ")) - def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - prime = [] - for i in factordb(n): - prime.append(i) + slowprint("\n[+] Please Wait ...\n ") + prime = primefactors(n) phi = 1 for i in prime: phi *= i-1 From daa5cc316ae4ad2dc3581e7362c4e4cc0f0d9a19 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Fri, 12 Apr 2019 16:28:11 +0200 Subject: [PATCH 026/122] Add files via upload --- fator_multi_prime.py | 134 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 fator_multi_prime.py diff --git a/fator_multi_prime.py b/fator_multi_prime.py new file mode 100644 index 0000000..340b5d7 --- /dev/null +++ b/fator_multi_prime.py @@ -0,0 +1,134 @@ +import random + +def primesbelow(N): + # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 + # Input N>=6, Returns a list of primes, 2 <= p < N + correction = N % 6 > 1 + N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6] + sieve = [True] * (N // 3) + sieve[0] = False + for i in range(int(N ** .5) // 3 + 1): + if sieve[i]: + k = (3 * i + 1) | 1 + sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1) + sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1) + return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]] + +smallprimeset = set(primesbelow(100000)) +_smallprimeset = 100000 +def isprime(n, precision=7): + # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time + if n < 1: + raise ValueError("Out of bounds, first argument must be > 0") + elif n <= 3: + return n >= 2 + elif n % 2 == 0: + return False + elif n < _smallprimeset: + return n in smallprimeset + + + d = n - 1 + s = 0 + while d % 2 == 0: + d //= 2 + s += 1 + + for repeat in range(precision): + a = random.randrange(2, n - 2) + x = pow(a, d, n) + + if x == 1 or x == n - 1: continue + + for r in range(s - 1): + x = pow(x, 2, n) + if x == 1: return False + if x == n - 1: break + else: return False + + return True + +# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ +def pollard_brent(n): + if n % 2 == 0: return 2 + if n % 3 == 0: return 3 + + y, c, m = random.randint(1, n-1), random.randint(1, n-1), random.randint(1, n-1) + g, r, q = 1, 1, 1 + while g == 1: + x = y + for i in range(r): + y = (pow(y, 2, n) + c) % n + + k = 0 + while k < r and g==1: + ys = y + for i in range(min(m, r-k)): + y = (pow(y, 2, n) + c) % n + q = q * abs(x-y) % n + g = gcd(q, n) + k += m + r *= 2 + if g == n: + while True: + ys = (pow(ys, 2, n) + c) % n + g = gcd(abs(x - ys), n) + if g > 1: + break + + return g + +smallprimes = primesbelow(1000) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 +def primefactors(n, sort=False): + factors = [] + + for checker in smallprimes: + while n % checker == 0: + factors.append(checker) + n //= checker + if checker > n: break + + if n < 2: return factors + + while n > 1: + if isprime(n): + factors.append(n) + break + factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent + factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent + n //= factor + + if sort: factors.sort() + + return factors + +def factorization(n): + factors = {} + for p1 in primefactors(n): + try: + factors[p1] += 1 + except KeyError: + factors[p1] = 1 + return factors + +totients = {} +def totient(n): + if n == 0: return 1 + + try: return totients[n] + except KeyError: pass + + tot = 1 + for p, exp in factorization(n).items(): + tot *= (p - 1) * p ** (exp - 1) + + totients[n] = tot + return tot + +def gcd(a, b): + if a == b: return a + while b > 0: a, b = b, a % b + return a + +def lcm(a, b): + return abs((a // gcd(a, b)) * b) From 92ba16cbe742b2a7ebde00e7490071600d8fa8e8 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:14:18 +0200 Subject: [PATCH 027/122] Update RSA.py --- RSA.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RSA.py b/RSA.py index 78fd234..ea8db1c 100644 --- a/RSA.py +++ b/RSA.py @@ -85,17 +85,17 @@ def banner(): import gmpy2 import requests from factordb import * - def factordb(n): f = FactorDB(n) f.connect() return f.get_factor_list() - gmpy2.get_context().precision=200 - m = gmpy2.iroot(c, e)[0] c = int(raw_input(">>> c = ")) n = int(raw_input(">>> n = ")) e = int(raw_input(">>> e = ")) + gmpy2.get_context().precision=200 + m = gmpy2.iroot(c, e)[0] + if pow(m,e) == c: slowprint("\n[+] Please Wait ... \033[95m\n") def hex_pair(x): @@ -137,7 +137,7 @@ def modinv(a,m): except ImportError: slowprint("\n[-] Module Not Setup") except ValueError: - slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") + slowprint("\n[-] c, e, n Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From 2044a368bddb3aba29f7a6bcb8891d13413465ba Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:15:04 +0200 Subject: [PATCH 028/122] Update RSA4.py --- RSA4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA4.py b/RSA4.py index 5e0f804..6f895ec 100644 --- a/RSA4.py +++ b/RSA4.py @@ -83,7 +83,7 @@ def banner(): slowprint("[+] The PlainText = ") print output except ValueError: - slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") + slowprint("\n[-] c,n,d Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From 931a8a08263e433430ae1de2c4a77c9d35565635 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:15:40 +0200 Subject: [PATCH 029/122] Update RSA5.py --- RSA5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA5.py b/RSA5.py index 9e7ad17..5fa7aef 100644 --- a/RSA5.py +++ b/RSA5.py @@ -152,7 +152,7 @@ def floorSqrt(n): premRSA(n,e,d,c) except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") + slowprint("\n[-] c,n,d,e Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From 804419f9d80998d25eae78a72a5f14d994aa6731 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:16:16 +0200 Subject: [PATCH 030/122] Update RSA7.py --- RSA7.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RSA7.py b/RSA7.py index a0f4478..490e20c 100644 --- a/RSA7.py +++ b/RSA7.py @@ -111,9 +111,9 @@ def modinv(a,m): output = (hex(decode)[2:].replace('L','')).decode("hex") slowprint("[+] The PlainText = ") print(output) - + except ValueError: - slowprint("\n[-] c,n,e,p Must Be Integar Number") + slowprint("\n[-] c,n,e,dp Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From c6f492b4bcff3313bf5596937fad37f324c69695 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:16:40 +0200 Subject: [PATCH 031/122] Update RSA8.py --- RSA8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA8.py b/RSA8.py index 5966afc..bc44c55 100644 --- a/RSA8.py +++ b/RSA8.py @@ -88,7 +88,7 @@ def hex_pair(x): except ImportError: slowprint("\n[-] Module Not Setup") except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") + slowprint("\n[-] c Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From bd9d3dfeb8f9145dc7e7db78d8ab6e21db0d4db8 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:17:31 +0200 Subject: [PATCH 032/122] Update RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py index 180fc98..2e13ccd 100644 --- a/RSA_chinese_remainder_theorem.py +++ b/RSA_chinese_remainder_theorem.py @@ -108,7 +108,7 @@ def chinese_remainder_theorem(p,q,dp,dq,chipher_text): slowprint("[+] The PlainText = ") print decode.decode("hex") except ValueError: - slowprint("\n[-] c,n,e,p Must Be Integar Number") + slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From 5ae0a05aa8ad2e3c243c655b75af0d34194fd026 Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:18:40 +0200 Subject: [PATCH 033/122] Update RSA_hasted.py --- RSA_hasted.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA_hasted.py b/RSA_hasted.py index 329f876..63540a3 100644 --- a/RSA_hasted.py +++ b/RSA_hasted.py @@ -135,7 +135,7 @@ def inv_pow(c, e): slowprint("[+] The PlainText = ") print decode.decode("hex") except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") + slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From 9b4ebcf3e8548b0674dfc8af79beb7db2dcde67d Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Mon, 15 Apr 2019 15:20:41 +0200 Subject: [PATCH 034/122] Update RSA5.py --- RSA5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA5.py b/RSA5.py index 5fa7aef..e625dbe 100644 --- a/RSA5.py +++ b/RSA5.py @@ -144,11 +144,11 @@ def floorSqrt(n): try: - slowprint("\n[+] Please Wait ... \033[95m\n") c = int(raw_input(">>> c = ")) n = int(raw_input(">>> n = ")) e = int(raw_input(">>> e = ")) d = int(raw_input(">>> d = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") premRSA(n,e,d,c) except ValueError: From a12817f1273b6b1fdbe7d3bf2d0b553d09341d5e Mon Sep 17 00:00:00 2001 From: X-Vector <30379192+X-Vector@users.noreply.github.com> Date: Sat, 20 Apr 2019 01:13:52 +0200 Subject: [PATCH 035/122] Update RSA_wiener.py --- RSA_wiener.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSA_wiener.py b/RSA_wiener.py index d2d4c80..3cbc98e 100644 --- a/RSA_wiener.py +++ b/RSA_wiener.py @@ -144,7 +144,7 @@ def wiener(n, e): except ImportError: slowprint("\n[-] Module Not Setup") except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") + slowprint("\n[-] c,n,e Must Be Integar Number") except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: From ad4c70abdfa3ba76f42668fc48d577ea7d9cdc18 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Tue, 18 Jun 2019 19:06:09 +0200 Subject: [PATCH 036/122] Set theme jekyll-theme-cayman --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file From 27e2a6f9f5107daacfcc6376d270c1303d7c7d25 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Tue, 18 Jun 2019 19:06:51 +0200 Subject: [PATCH 037/122] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b42cad4..21d5a8c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# X-RSA For RSA Attacks : +# X-RSA - X-RSA V0.2 contains a many of attack types such as Hasted, Fermat, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attack. - New Attack Added To X-RSA V0.2 And Fixing Many Error in V0.1 @@ -7,8 +7,8 @@ - Written By [Python] -# Installing and Open Tool : -1 - install tool : +# Installing and Open Tool +1 - install tool ``` git clone https://github.com/X-Vector/X-RSA.git ``` @@ -17,11 +17,11 @@ git clone https://github.com/X-Vector/X-RSA.git apt install libgmp-dev libmpfr-dev libmpc-dev pip install -r requirement.txt ``` -3 - Open Tool : +3 - Open Tool ``` python Attack.py ``` -# Screenshots : +# Screenshots ![X-RSA](https://e.top4top.net/p_1196pglz71.png "X-RSA in Action") From 8357bafbe1b14127a328b8ed2b2b8749c8b537e9 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Tue, 18 Jun 2019 19:07:13 +0200 Subject: [PATCH 038/122] Delete _config.yml --- _config.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 _config.yml diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c419263..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file From f321af2cf3c3e72b3b40ee2fc64b5b2be31ae084 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:25 +0200 Subject: [PATCH 039/122] Delete Attack.py --- Attack.py | 136 ------------------------------------------------------ 1 file changed, 136 deletions(-) delete mode 100644 Attack.py diff --git a/Attack.py b/Attack.py deleted file mode 100644 index 1335641..0000000 --- a/Attack.py +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s + '\n': - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() - -print(""" -[1] - Attack(c,n,e) \033[92m -[2] - Attack(c,p,q,e) \033[96m -[3] - Attack (c,n,e,{p or q}) -[4] - Attack (c,n,e,dp) -[5] - Attack(c,n,d,e,phi) \033[93m -[6] - Attack(c1,c2,c3,n1,n2,n3,e=3) \033[95m [ Hasted ] -[7] - Attack(n,limit) \033[92m [ Fermat ] -[8] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] -[9] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] -[10] - Attack(n,e) \033[95m [ Wiener ] -[11] - Attack(c,n,d)\033[0m -[12] - Attack(c,d,n,e)\033[92m -[13] - Attack(c,n,e) \033[93m [ Multi Prime Number ] -[14] - Attack(c,e = 3)\033[0m -[0] - Exit \033[92m - """) -x = int(input(">>> ")) -if x == 1: - os.system(clear) - import RSA -elif x == 2: - os.system(clear) - import RSA2 -elif x == 3: - os.system(clear) - import RSA6 -elif x == 4: - os.system(clear) - import RSA7 -elif x == 5: - os.system(clear) - import RSA3 -elif x == 6: - os.system(clear) - import RSA_hasted -elif x == 7: - os.system(clear) - import RSA_fermat -elif x == 8: - os.system(clear) - import RSA_common_modulus -elif x == 9: - os.system(clear) - import RSA_chinese_remainder_theorem -elif x == 10: - os.system(clear) - import RSA_wiener -elif x == 11: - os.system(clear) - import RSA4 -elif x == 12: - os.system(clear) - import RSA5 -elif x == 13: - os.system(clear) - import RSA_multiPrime1 -elif x == 14: - os.system(clear) - import RSA8 -else: - slowprint("\t\t\t[+] Thanx For using T00l <3") - exit() From 638f2e5a513898391881d52391ad44769ab32b4a Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:30 +0200 Subject: [PATCH 040/122] Delete RSA.py --- RSA.py | 146 --------------------------------------------------------- 1 file changed, 146 deletions(-) delete mode 100644 RSA.py diff --git a/RSA.py b/RSA.py deleted file mode 100644 index ea8db1c..0000000 --- a/RSA.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() - -# Example 1 : -#c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 -#n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 -#e = 65537 - -# Example 2 : -#n = 95927091022214131235859313618337025685657931350656500630264132698389852599510198358308813869652616688807245375001990146888881030682552800587836982145527192151998189057703804830882536718184311723290034393819853924918814439601355616561237190273205228499357454477829605938284765657202538703493014172555332956153 -#e = 3 -#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 - -try: - import binascii - import gmpy2 - import requests - from factordb import * - def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - gmpy2.get_context().precision=200 - m = gmpy2.iroot(c, e)[0] - - if pow(m,e) == c: - slowprint("\n[+] Please Wait ... \033[95m\n") - def hex_pair(x): - return ('0' * (len(x) % 2)) + x - m_hex = '{:x}'.format(m) - m_hex = hex_pair(m_hex) - msg = binascii.unhexlify(m_hex) - slowprint("[+] The PlainText = ") - print(msg.decode()) - else: - slowprint("\n[+] Please Wait ... \033[95m\n") - factordb = factordb(n) - q = factordb[0] - p = factordb[1] - phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) - - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("RSA Hello") - else : - return x%m - - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n :( ") - slowprint("\n[!] Try To Use MultiPrime Attack ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c, e, n Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From e00008332515f649057801862d833a49552d7bc1 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:35 +0200 Subject: [PATCH 041/122] Delete RSA2.py --- RSA2.py | 101 -------------------------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 RSA2.py diff --git a/RSA2.py b/RSA2.py deleted file mode 100644 index 74273da..0000000 --- a/RSA2.py +++ /dev/null @@ -1,101 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - - - -#c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 -#p = 238324208831434331628131715304428889871 -#q = 296805874594538235115008173244022912163 -#e = 3 - - -try: - import gmpy - c = int(raw_input(">>> c = ")) - p = int(raw_input(">>> p = ")) - q = int(raw_input(">>> q = ")) - e = int(raw_input(">>> e = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - n = p*q - x = (p-1)*(q-1) - d = gmpy.invert(e,x) - m = hex(pow(c,d,n))[2:] - decode = m.decode('hex') - slowprint("[+] The PlainText = ") - print(decode) - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 51611cb016f431ea34104acc194c7dd22a8c6d43 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:40 +0200 Subject: [PATCH 042/122] Delete RSA3.py --- RSA3.py | 95 --------------------------------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 RSA3.py diff --git a/RSA3.py b/RSA3.py deleted file mode 100644 index 23a766f..0000000 --- a/RSA3.py +++ /dev/null @@ -1,95 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - - -#c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 -#n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 -#d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 -#e = 65537 -#phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - d = int(raw_input(">>> d = ")) - e = int(raw_input(">>> e = ")) - phi = int(raw_input(">>> phi = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - n = hex(pow(c,d,n))[2:] - decode = (n.replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print decode -except ValueError: - slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From fcbf36aebc40af652a383cc7b55e69669d195df3 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:45 +0200 Subject: [PATCH 043/122] Delete RSA4.py --- RSA4.py | 92 --------------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 RSA4.py diff --git a/RSA4.py b/RSA4.py deleted file mode 100644 index 6f895ec..0000000 --- a/RSA4.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - -#n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -#d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 -#c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 - - - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - d = int(raw_input(">>> d = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print output -except ValueError: - slowprint("\n[-] c,n,d Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From d9fdbb7402a036744eaadb2ff00fb9b6f98c8847 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:30:51 +0200 Subject: [PATCH 044/122] Delete RSA5.py --- RSA5.py | 161 -------------------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 RSA5.py diff --git a/RSA5.py b/RSA5.py deleted file mode 100644 index e625dbe..0000000 --- a/RSA5.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() -try: - from Crypto.PublicKey import RSA - import sympy as sp - import math -except ImportError: - slowprint("\n[-] Module Not Setup") -""" -#n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 -#e = 65537 -#d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 -#c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 -""" - -def premRSA(n,e,d,c): - bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) - bitLenD0 = 2048 - - assert bitLenD0 >= bitLenN/2 - - d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) - c = pow(c,d,n) - plaintext = str(bytearray(hex(c)[2:])).replace("L","") - slowprint("[+] The PlainText = ") - print(plaintext.decode("hex")) - -def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): - test = pow(3, e, n) - test2 = pow(5, e, n) - for k in range(1,e): - d = ((k * n + 1) // e) - d >>= d0BitSize - d <<= d0BitSize - d |= d0 - if((e * d) % k == 1): - if pow(test, d, n) == 3: - if pow(test2, d, n) == 5: - totientN = (e*d - 1) // k - b = totientN - n - 1 - discriminant = b*b - 4*n - root = floorSqrt(discriminant) - if(root*root != discriminant): - continue - p = (-b + root) // 2 - q = n // p - return d - - -def extended_gcd(aa, bb): - lastremainder, remainder = abs(aa), abs(bb) - x, lastx, y, lasty = 0, 1, 1, 0 - while remainder: - lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) - x, lastx = lastx - quotient*x, x - y, lasty = lasty - quotient*y, y - return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) - -def modinv(a, m): - g, x, y = extended_gcd(a, m) - if g != 1: - raise ValueError - return x % m - -def floorSqrt(n): - x = n - y = (x + 1) // 2 - while y < x: - x = y - y = (x + n // x) // 2 - return x - - - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - d = int(raw_input(">>> d = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - premRSA(n,e,d,c) - -except ValueError: - slowprint("\n[-] c,n,d,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 91a5752e57c523c6fa1ab6b5b2143aefa77df18a Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:03 +0200 Subject: [PATCH 045/122] Delete RSA6.py --- RSA6.py | 115 -------------------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 RSA6.py diff --git a/RSA6.py b/RSA6.py deleted file mode 100644 index ff46496..0000000 --- a/RSA6.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() -import binascii - -""" -p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 -c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 -e = 65537 -n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 -""" -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - p = int(raw_input(">>> p = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - q = n/p - phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("RSA Hello") - else : - return x%m - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except ValueError: - slowprint("\n[-] c,n,e,p Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 903b3681fead354254264677169e9664479b0062 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:08 +0200 Subject: [PATCH 046/122] Delete RSA7.py --- RSA7.py | 122 -------------------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 RSA7.py diff --git a/RSA7.py b/RSA7.py deleted file mode 100644 index 490e20c..0000000 --- a/RSA7.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() -import binascii -""" -e = 65537 -n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 -dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 -c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 -""" - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - dp = int(raw_input(">>> dp = ")) - - mp = (dp * e) - 1 - for i in range(2,1000000): - p = (mp / i) + 1 - if n % p == 0: - break - q = n/p - slowprint("\n[+] Please Wait ... \033[95m\n") - phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("[-] Sorry") - else : - return x%m - - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except ValueError: - slowprint("\n[-] c,n,e,dp Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From cc753c89886e10142e26eb4440f248db4fb071b8 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:14 +0200 Subject: [PATCH 047/122] Delete RSA8.py --- RSA8.py | 97 --------------------------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 RSA8.py diff --git a/RSA8.py b/RSA8.py deleted file mode 100644 index bc44c55..0000000 --- a/RSA8.py +++ /dev/null @@ -1,97 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() - - - -# Example -#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 - -try: - import gmpy2 - import binascii - gmpy2.get_context().precision=99999999999999999 - c = int(raw_input(">>> c = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - m = gmpy2.iroot(c, 3)[0] - assert pow(m,3) == c - def hex_pair(x): - return ('0' * (len(x) % 2)) + x - m_hex = '{:x}'.format(m) - m_hex = hex_pair(m_hex) - msg = binascii.unhexlify(m_hex) - slowprint("[+] The PlainText = ") - print(msg.decode()) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From a529d978df749938e54bc8744fccd3162450683a Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:19 +0200 Subject: [PATCH 048/122] Delete RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 117 ------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 RSA_chinese_remainder_theorem.py diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py deleted file mode 100644 index 2e13ccd..0000000 --- a/RSA_chinese_remainder_theorem.py +++ /dev/null @@ -1,117 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() -""" -#Example - -c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 -p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 -q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 -dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 -dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 -""" - - - - -try: - c = int(raw_input(">>> c = ")) - p = int(raw_input(">>> p = ")) - q = int(raw_input(">>> q = ")) - dp = int(raw_input(">>> dp = ")) - dp = int(raw_input(">>> dq = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - - def egcd(a,b): - if a == 0: - return (b, 0, 1) - else: - g, y, x = egcd(b % a, a) - return (g, x - (b / a) * y, y) - def modinv(a,m): - g, x, y = egcd(a, m) - if g != 1: - raise Exception('modular inverse does not exist') - else: - return x % m - def chinese_remainder_theorem(p,q,dp,dq,chipher_text): - q_inv = modinv(p , q) - m1 = pow(chipher_text,dp,p) - m2 = pow(chipher_text,dq,q) - h = (q_inv*(m1-m2)) % p - return m2 + h * q - decode = hex(chinese_remainder_theorem(p,q,dp,dq,c))[2:].replace('L','') - slowprint("[+] The PlainText = ") - print decode.decode("hex") -except ValueError: - slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 61205cc75cedcbee9ab04a99c813715547cc7b86 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:24 +0200 Subject: [PATCH 049/122] Delete RSA_common_modulus.py --- RSA_common_modulus.py | 119 ------------------------------------------ 1 file changed, 119 deletions(-) delete mode 100644 RSA_common_modulus.py diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py deleted file mode 100644 index 4712f7f..0000000 --- a/RSA_common_modulus.py +++ /dev/null @@ -1,119 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() -try: - import gmpy2 - from Crypto.Util.number import * - c1 = int(raw_input(">>> c1 = ")) - c2 = int(raw_input(">>> c2 = ")) - e1 = int(raw_input(">>> e1 = ")) - e2 = int(raw_input(">>> e2 = ")) - n = int(raw_input(">>> n = ")) - - slowprint("\n[+] Please Wait ... \033[95m\n") - - def egcd(a, b): - if (a == 0): - return (b, 0, 1) - else: - g, y, x = egcd(b % a, a) - return (g, x - (b // a) * y, y) - - # Calculates a^{b} mod n when b is negative - def neg_pow(a, b, n): - assert b < 0 - assert GCD(a, n) == 1 - res = int(gmpy2.invert(a, n)) - res = pow(res, b*(-1), n) - return res - - - def common_modulus(e1, e2, n, c1, c2): - g, a, b = egcd(e1, e2) - if a < 0: - c1 = neg_pow(c1, a, n) - else: - c1 = pow(c1, a, n) - if b < 0: - c2 = neg_pow(c2, b, n) - else: - c2 = pow(c2, b, n) - ct = c1*c2 % n - m = int(gmpy2.iroot(ct, g)[0]) - return long_to_bytes(m) - slowprint("[+] The PlainText = ") - print common_modulus(e1, e2, n, c1, c2) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From d1c93460e3e74c3e18a96f114757e79748e832ca Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:28 +0200 Subject: [PATCH 050/122] Delete RSA_fermat.py --- RSA_fermat.py | 129 -------------------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 RSA_fermat.py diff --git a/RSA_fermat.py b/RSA_fermat.py deleted file mode 100644 index ac849c4..0000000 --- a/RSA_fermat.py +++ /dev/null @@ -1,129 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s + '\n': - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - -n = int(raw_input(">>> n = ")) -limit = int(raw_input(">>> limit = ")) - -slowprint("\n[+] Please Wait ... \033[95m\n") - - -import sys -import math -import Crypto.PublicKey.RSA -import fractions -import random -import argparse -class Fermat(object): - def accueil(self): - slowprint("[+] Getting info ... ") - def carre_parfait(self, x): - if x < 1: - return(False) - sqrt_x = math.sqrt(x) - return (sqrt_x == int(math.floor(sqrt_x))) - def fermat(self,n): - a = 2*math.ceil(math.sqrt(n)) + 1 - aux = 2 * a +1 - n4 = 4 * n - c = pow(a, 2) - n4 - while not carre_parfait(c): - c += aux - a += 1 - aux += 2 - b = int(math.sqrt(c)) - p = (a - b) // 2 - q = (a + b) // 2 - if (p*q != n): - slowprint("Error!") - exit(0) - return (p, q) - def indicatrice_euler(self, p, q): - return((p - 1) * (q - 1)) - def bezout(self, a, b): - if a == 0 and b == 0: - return (0, 0, 0) - if b == 0: - return (a // abs(a), 0, abs(a)) - (u, v, p) = self.bezout(b, a % b) - return (v, (u - v * (a // b)), p) - def inv_modulo(self, x, m): - (u, _, p) = self.bezout(x, m) - return u % abs(m) - def __init__(self, n, e): - self.accueil() - try: - (p, q) = self.fermat(n, e) - except: - slowprint("\n[-] Sorry This RSA public key isn't a valide candidate for a Fermat Attack\n") - exit() - print("\n\t[+] Factorization = {} * {}\n".format(p,q)) - phi = indicatrice_euler(p,q) - self.d = inv_modulo(e, phi) - print("[+] d = {}\n".format(d)) - -Fermat(n,limit) From a530bbc16a5be00279c592e1d54c9bcd0d0f6ef8 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:33 +0200 Subject: [PATCH 051/122] Delete RSA_hasted.py --- RSA_hasted.py | 146 -------------------------------------------------- 1 file changed, 146 deletions(-) delete mode 100644 RSA_hasted.py diff --git a/RSA_hasted.py b/RSA_hasted.py deleted file mode 100644 index 63540a3..0000000 --- a/RSA_hasted.py +++ /dev/null @@ -1,146 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - - - -# N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 -# C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 -# N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 -# C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 -# N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 -# C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 - - - -def chinese_remainder(n, a): - sum = 0 - prod = functools.reduce(lambda a, b: a*b, n) - for n_i, a_i in zip(n, a): - p = prod // n_i - sum += a_i * mul_inv(p, n_i) * p - return sum % prod - -def mul_inv(a, b): - b0 = b - x0, x1 = 0, 1 - if b == 1: return 1 - while a > 1: - q = a // b - a, b = b, a%b - x0, x1 = x1 - q * x0, x0 - if x1 < 0: x1 += b0 - return x1 - -def inv_pow(c, e): - low = -1 - high = c+1 - while low + 1 < high: - m = (low + high) // 2 - p = pow(m, e) - if p < c: - low = m - else: - high = m - m = high - assert pow(m, e) == c - return m - - -try: - import functools - import itertools - - C1 = int(raw_input(">>> c1 = ")) - C2 = int(raw_input(">>> c2 = ")) - C3 = int(raw_input(">>> c3 = ")) - N1 = int(raw_input(">>> n1 = ")) - N2 = int(raw_input(">>> n2 = ")) - N3 = int(raw_input(">>> n3 = ")) - N = [N1, N2, N3] - C = [C1, C2, C3] - e = len(N) - print "e = ",e - slowprint("\n[+] Please Wait ... \033[95m\n") - - a = chinese_remainder(N, C) - for n, c in zip(N, C): - assert a % n == c - m = inv_pow(a, e) - decode = (hex(m)[2:]).replace('L','') - slowprint("[+] The PlainText = ") - print decode.decode("hex") -except ValueError: - slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except ImportError: - slowprint("\n[-] Module Not Setup") -except: - slowprint("\n[-] False Attack !") From 3348fdab31eb0646031654bf114af9ad1b00be40 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:39 +0200 Subject: [PATCH 052/122] Delete RSA_multiPrime1.py --- RSA_multiPrime1.py | 118 --------------------------------------------- 1 file changed, 118 deletions(-) delete mode 100644 RSA_multiPrime1.py diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py deleted file mode 100644 index bd0c44a..0000000 --- a/RSA_multiPrime1.py +++ /dev/null @@ -1,118 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) -banner() - -""" -c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 -n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 -e= 65537 -prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] -""" - -try: - from fator_multi_prime import * - import binascii - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - slowprint("\n[+] Please Wait ...\n ") - prime = primefactors(n) - phi = 1 - for i in prime: - phi *= i-1 - def egcd(a, b): - if a == 0: - return (b, 0, 1) - g, y, x = egcd(b%a,a) - return (g, x - (b//a) * y, y) - def modinv(a, m): - g, x, y = egcd(a, m) - if g != 1: - raise Exception('No modular inverse') - return x%m - d = modinv(e, phi) - m = pow(c, d, n) - def hex_pair(x): - return ('0' * (len(x) % 2)) + x - m_hex = '{:x}'.format(m) - m_hex = hex_pair(m_hex) - msg = binascii.unhexlify(m_hex) - slowprint("\n[+] The PlainText = ") - print(msg.decode(errors="ignore")) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,n,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except Exception: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("[-] False Attack !") From b645842fd0c3e39f775477f37e0926027347a0d2 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:47 +0200 Subject: [PATCH 053/122] Delete RSA_wiener.py --- RSA_wiener.py | 155 -------------------------------------------------- 1 file changed, 155 deletions(-) delete mode 100644 RSA_wiener.py diff --git a/RSA_wiener.py b/RSA_wiener.py deleted file mode 100644 index 3cbc98e..0000000 --- a/RSA_wiener.py +++ /dev/null @@ -1,155 +0,0 @@ -import sys -import platform,os -from urllib2 import * -from platform import system - -def slowprint(s): - for c in s : - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s - -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.2 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - - """ % (R, W,R)) -banner() - -#Example : -""" -n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 -c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 - -""" -try: - import random - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - - slowprint("\n[+] Please Wait ... \033[95m\n") - - def division_euclidienne(a, b): - return (a // b, a % b) - def fraction_continue(n, d): - developpement = [] - a = n - b = d - while b != 0: - (q,r) = division_euclidienne(a,b) - developpement.append(q) - a = b - b = r - return (developpement) - def reduites_fraction_continue(a): - l=len(a) - reduites=[] - h0 = 1 - h1 = 0 - k0 = 0 - k1 = 1 - count = 0 - while count < l: - h = a[count] * h1 + h0 - h0 = h1 - h1 = h - k = a[count] * k1 + k0 - k0 = k1 - k1 = k - reduites.append((k,h)) - count += 1 - return (reduites) - def wiener(n, e): - fc = fraction_continue(e, n) - reduites = reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - slowprint("[+] Getting d ... \033[95m\n") - return (reduites[i][1]) - else: - print("[-] Sorry it's Not Wiener Attack\n") - exit(0) - - d = wiener(n,e) - print "\nd = ",d - check = raw_input("\nYou Have Cipher [y/n] : ") - if check == "y" or check == "yes": - c = int(raw_input(">>> c = ")) - slowprint("[+] Getting PlainText ... \033[92m\n") - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = \033[92m") - print output - else : - slowprint("[+] Thanx For Using X-RSA \033[95m") - exit() - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,n,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except Exception: - slowprint("\n[-] Wrong Data") -except: - slowprint("\n[-] False Attack !") From 4ebffc116463d1cc1b7d19485e14b9ef643d261f Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:31:54 +0200 Subject: [PATCH 054/122] Delete factordb.py --- factordb.py | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 factordb.py diff --git a/factordb.py b/factordb.py deleted file mode 100644 index 2109ea7..0000000 --- a/factordb.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function, unicode_literals -import requests - - -ENDPOINT = "http://factordb.com/api" - - -class FactorDB(): - def __init__(self, n): - self.n = n - self.result = None - - def connect(self, reconnect=False): - if self.result and not reconnect: - return self.result - self.result = requests.get(ENDPOINT, params={"query": str(self.n)}) - return self.result - - def get_id(self): - if self.result: - return self.result.json().get("id") - return None - - def get_status(self): - if self.result: - return self.result.json().get("status") - return None - - def get_factor_from_api(self): - if self.result: - return self.result.json().get("factors") - return None - - def get_factor_list(self): - """ - get_factors: [['2', 3], ['3', 2]] - Returns: [2, 2, 2, 3, 3] - """ - factors = self.get_factor_from_api() - if not factors: - return [] - ml = [[int(x)] * y for x, y in factors] - return [y for x in ml for y in x] From dc83c872d74db2a41f9e53bd27fc74fb25f46d0c Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:32:00 +0200 Subject: [PATCH 055/122] Delete fator_multi_prime.py --- fator_multi_prime.py | 134 ------------------------------------------- 1 file changed, 134 deletions(-) delete mode 100644 fator_multi_prime.py diff --git a/fator_multi_prime.py b/fator_multi_prime.py deleted file mode 100644 index 340b5d7..0000000 --- a/fator_multi_prime.py +++ /dev/null @@ -1,134 +0,0 @@ -import random - -def primesbelow(N): - # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 - # Input N>=6, Returns a list of primes, 2 <= p < N - correction = N % 6 > 1 - N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6] - sieve = [True] * (N // 3) - sieve[0] = False - for i in range(int(N ** .5) // 3 + 1): - if sieve[i]: - k = (3 * i + 1) | 1 - sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1) - sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1) - return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]] - -smallprimeset = set(primesbelow(100000)) -_smallprimeset = 100000 -def isprime(n, precision=7): - # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time - if n < 1: - raise ValueError("Out of bounds, first argument must be > 0") - elif n <= 3: - return n >= 2 - elif n % 2 == 0: - return False - elif n < _smallprimeset: - return n in smallprimeset - - - d = n - 1 - s = 0 - while d % 2 == 0: - d //= 2 - s += 1 - - for repeat in range(precision): - a = random.randrange(2, n - 2) - x = pow(a, d, n) - - if x == 1 or x == n - 1: continue - - for r in range(s - 1): - x = pow(x, 2, n) - if x == 1: return False - if x == n - 1: break - else: return False - - return True - -# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ -def pollard_brent(n): - if n % 2 == 0: return 2 - if n % 3 == 0: return 3 - - y, c, m = random.randint(1, n-1), random.randint(1, n-1), random.randint(1, n-1) - g, r, q = 1, 1, 1 - while g == 1: - x = y - for i in range(r): - y = (pow(y, 2, n) + c) % n - - k = 0 - while k < r and g==1: - ys = y - for i in range(min(m, r-k)): - y = (pow(y, 2, n) + c) % n - q = q * abs(x-y) % n - g = gcd(q, n) - k += m - r *= 2 - if g == n: - while True: - ys = (pow(ys, 2, n) + c) % n - g = gcd(abs(x - ys), n) - if g > 1: - break - - return g - -smallprimes = primesbelow(1000) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 -def primefactors(n, sort=False): - factors = [] - - for checker in smallprimes: - while n % checker == 0: - factors.append(checker) - n //= checker - if checker > n: break - - if n < 2: return factors - - while n > 1: - if isprime(n): - factors.append(n) - break - factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent - factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent - n //= factor - - if sort: factors.sort() - - return factors - -def factorization(n): - factors = {} - for p1 in primefactors(n): - try: - factors[p1] += 1 - except KeyError: - factors[p1] = 1 - return factors - -totients = {} -def totient(n): - if n == 0: return 1 - - try: return totients[n] - except KeyError: pass - - tot = 1 - for p, exp in factorization(n).items(): - tot *= (p - 1) * p ** (exp - 1) - - totients[n] = tot - return tot - -def gcd(a, b): - if a == b: return a - while b > 0: a, b = b, a % b - return a - -def lcm(a, b): - return abs((a // gcd(a, b)) * b) From 03a891a4b91bce4baf9bb69d945d3d47ca50af32 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:34:37 +0200 Subject: [PATCH 056/122] Add files via upload --- Attack.py | 72 +++ Factorization.py | 53 +++ RSA.py | 58 +++ RSA2.py | 35 ++ RSA3.py | 30 ++ RSA4.py | 27 ++ RSA5.py | 92 ++++ RSA6.py | 45 ++ RSA7.py | 52 ++ RSA8.py | 33 ++ RSA_chinese_remainder_theorem.py | 52 ++ RSA_common_modulus.py | 54 +++ RSA_hasted.py | 79 ++++ RSA_multiPrime1.py | 55 +++ RSA_wiener.py | 89 ++++ banner.py | 70 +++ ecm.py | 135 ++++++ factordb.py | 45 ++ fermat.py | 19 + qs.py | 788 +++++++++++++++++++++++++++++++ 20 files changed, 1883 insertions(+) create mode 100644 Attack.py create mode 100644 Factorization.py create mode 100644 RSA.py create mode 100644 RSA2.py create mode 100644 RSA3.py create mode 100644 RSA4.py create mode 100644 RSA5.py create mode 100644 RSA6.py create mode 100644 RSA7.py create mode 100644 RSA8.py create mode 100644 RSA_chinese_remainder_theorem.py create mode 100644 RSA_common_modulus.py create mode 100644 RSA_hasted.py create mode 100644 RSA_multiPrime1.py create mode 100644 RSA_wiener.py create mode 100644 banner.py create mode 100644 ecm.py create mode 100644 factordb.py create mode 100644 fermat.py create mode 100644 qs.py diff --git a/Attack.py b/Attack.py new file mode 100644 index 0000000..ff91887 --- /dev/null +++ b/Attack.py @@ -0,0 +1,72 @@ +from banner import * +banner() +print(""" +[1] - Attacks +[2] - Factorization Number +""") +check = int(raw_input(">>> ")) +if check == 2: + import Factorization + +elif check == 1: + banner() + print(""" +[1] - Attack(c,n,e) \033[92m +[2] - Attack(c,p,q,e) \033[96m +[3] - Attack (c,n,e,{p or q}) +[4] - Attack (c,n,e,dp) +[5] - Attack(c,n,d,e,phi) \033[93m +[6] - Attack(c1,c2,c3,n1,n2,n3,e=3) \033[95m [ Hasted ] +[7] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] +[8] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] +[9] - Attack(n,e) \033[95m [ Wiener ] +[10] - Attack(c,n,d)\033[0m +[11] - Attack(c,d,n,e)\033[92m +[12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] +[13] - Attack(c,e = 3)\033[0m +[0] - Exit \033[92m + """) + x = int(raw_input(">>> ")) + if x == 1: + os.system(clear) + import RSA + elif x == 2: + os.system(clear) + import RSA2 + elif x == 3: + os.system(clear) + import RSA6 + elif x == 4: + os.system(clear) + import RSA7 + elif x == 5: + os.system(clear) + import RSA3 + elif x == 6: + os.system(clear) + import RSA_hasted + elif x == 7: + os.system(clear) + import RSA_common_modulus + elif x == 8: + os.system(clear) + import RSA_chinese_remainder_theorem + elif x == 9: + os.system(clear) + import RSA_wiener + elif x == 10: + os.system(clear) + import RSA4 + elif x == 11: + os.system(clear) + import RSA5 + elif x == 12: + os.system(clear) + import RSA_multiPrime1 + elif x == 13: + os.system(clear) + import RSA8 + else: + exit() +else: + exit() diff --git a/Factorization.py b/Factorization.py new file mode 100644 index 0000000..e298bf5 --- /dev/null +++ b/Factorization.py @@ -0,0 +1,53 @@ +from banner import * +banner() + +from factordb import * +from fermat import * +from ecm import * +from qs import * + +print(""" +[1] - Factordb Factorization \033[92m +[2] - Fermet Factorization \033[96m +[3] - ECM Factorization \033[93m +[4] - Quadratic sieve Factorization \033[95m +[0] - Exit \033[92m + """) + +x = int(raw_input(">>> ")) +#Factordb +if x == 1: + + n = int(raw_input("%s\nn = %s"%(B,B))) + print "\n[+] Please Wait ...\n" + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + print "%sprimes =%s"%(Y,Y),"%s"%(G),factordb(n) + +#Fermet +elif x == 2: + n = int(raw_input("%s\nn = %s"%(B,B))) + print "\n[+] Please Wait ...\n" + fermat(n) + +#ECM +elif x == 3: + n = int(raw_input("%s\nn = %s"%(B,B))) + print "\n[+] Please Wait ...\n" + print "%sprimes =%s"%(Y,Y),"%s"%(G),primefactors(n) + +elif x == 4: + N = int(raw_input("%s\nn = %s"%(B,B))) + if not factorise(N): + print("Number Must Be Greater Than 0 and Must Be Integer") + elif factorise(N) == "Long": + print("N is Too Long ") + else: + print "\n[+] Please Wait ...\n" + print "%sprimes =%s"%(Y,Y),"%s"%(G),factorise(N) + +else: + exit() diff --git a/RSA.py b/RSA.py new file mode 100644 index 0000000..83d7520 --- /dev/null +++ b/RSA.py @@ -0,0 +1,58 @@ +from banner import * +banner() + +# Example : +#c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 +#n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 +#e = 65537 + +try: + import binascii + import gmpy2 + from factordb import * + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + factordb = factordb(n) + q = factordb[0] + p = factordb[1] + phi = (p-1)*(q-1) + def egcd(a,b): + if a == 0 : + return(b,0,1) + else: + g,y,x = egcd(b%a,a) + return (g,x-(b/a)*y,y) + + def modinv(a,m): + g,x,y = egcd(a,m) + if g != 1: + raise Expection("RSA Hello") + else : + return x%m + + d = modinv(e,phi) + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print(output) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n :( ") + slowprint("\n[!] Try To Use MultiPrime Attack ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c, e, n Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA2.py b/RSA2.py new file mode 100644 index 0000000..1aa823a --- /dev/null +++ b/RSA2.py @@ -0,0 +1,35 @@ +from banner import * +banner() + + +#c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 +#p = 238324208831434331628131715304428889871 +#q = 296805874594538235115008173244022912163 +#e = 3 + + +try: + import gmpy + c = int(raw_input(">>> c = ")) + p = int(raw_input(">>> p = ")) + q = int(raw_input(">>> q = ")) + e = int(raw_input(">>> e = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + n = p*q + phi = (p-1)*(q-1) + d = gmpy.invert(e,phi) + m = hex(pow(c,d,n))[2:] + decode = m.decode('hex') + slowprint("[+] The PlainText = ") + print(decode) + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA3.py b/RSA3.py new file mode 100644 index 0000000..a9fc6eb --- /dev/null +++ b/RSA3.py @@ -0,0 +1,30 @@ +from banner import * +banner() + + +#c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 +#n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 +#d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 +#e = 65537 +#phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 + + +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + d = int(raw_input(">>> d = ")) + e = int(raw_input(">>> e = ")) + phi = int(raw_input(">>> phi = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + n = hex(pow(c,d,n))[2:] + decode = (n.replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print decode +except ValueError: + slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA4.py b/RSA4.py new file mode 100644 index 0000000..381617d --- /dev/null +++ b/RSA4.py @@ -0,0 +1,27 @@ +from banner import * +banner() + +#n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +#d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 +#c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 + + + + +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + d = int(raw_input(">>> d = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print output +except ValueError: + slowprint("\n[-] c,n,d Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA5.py b/RSA5.py new file mode 100644 index 0000000..3985d40 --- /dev/null +++ b/RSA5.py @@ -0,0 +1,92 @@ +from banner import * +banner() + +try: + from Crypto.PublicKey import RSA + import sympy as sp + import math +except ImportError: + slowprint("\n[-] Module Not Setup") +""" +#n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 +#e = 65537 +#d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 +#c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 +""" + +def premRSA(n,e,d,c): + bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) + bitLenD0 = 2048 + + assert bitLenD0 >= bitLenN/2 + + d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) + c = pow(c,d,n) + plaintext = str(bytearray(hex(c)[2:])).replace("L","") + slowprint("[+] The PlainText = ") + print(plaintext.decode("hex")) + +def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): + test = pow(3, e, n) + test2 = pow(5, e, n) + for k in range(1,e): + d = ((k * n + 1) // e) + d >>= d0BitSize + d <<= d0BitSize + d |= d0 + if((e * d) % k == 1): + if pow(test, d, n) == 3: + if pow(test2, d, n) == 5: + totientN = (e*d - 1) // k + b = totientN - n - 1 + discriminant = b*b - 4*n + root = floorSqrt(discriminant) + if(root*root != discriminant): + continue + p = (-b + root) // 2 + q = n // p + return d + + +def extended_gcd(aa, bb): + lastremainder, remainder = abs(aa), abs(bb) + x, lastx, y, lasty = 0, 1, 1, 0 + while remainder: + lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) + x, lastx = lastx - quotient*x, x + y, lasty = lasty - quotient*y, y + return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) + +def modinv(a, m): + g, x, y = extended_gcd(a, m) + if g != 1: + raise ValueError + return x % m + +def floorSqrt(n): + x = n + y = (x + 1) // 2 + while y < x: + x = y + y = (x + n // x) // 2 + return x + + + + +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + d = int(raw_input(">>> d = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + premRSA(n,e,d,c) + +except ValueError: + slowprint("\n[-] c,n,d,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA6.py b/RSA6.py new file mode 100644 index 0000000..d8d78ff --- /dev/null +++ b/RSA6.py @@ -0,0 +1,45 @@ +from banner import * +banner() + +import binascii + +""" +p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 +c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 +e = 65537 +n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 +""" +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + p = int(raw_input(">>> p = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + q = n/p + phi = (p-1)*(q-1) + def egcd(a,b): + if a == 0 : + return(b,0,1) + else: + g,y,x = egcd(b%a,a) + return (g,x-(b/a)*y,y) + def modinv(a,m): + g,x,y = egcd(a,m) + if g != 1: + raise Expection("RSA Hello") + else : + return x%m + d = modinv(e,phi) + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print(output) + +except ValueError: + slowprint("\n[-] c,n,e,p Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA7.py b/RSA7.py new file mode 100644 index 0000000..cb69a64 --- /dev/null +++ b/RSA7.py @@ -0,0 +1,52 @@ +from banner import * +banner() + +import binascii +""" +e = 65537 +n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 +dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 +c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 +""" + +try: + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + dp = int(raw_input(">>> dp = ")) + + mp = (dp * e) - 1 + for i in range(2,1000000): + p = (mp / i) + 1 + if n % p == 0: + break + q = n/p + slowprint("\n[+] Please Wait ... \033[95m\n") + phi = (p-1)*(q-1) + def egcd(a,b): + if a == 0 : + return(b,0,1) + else: + g,y,x = egcd(b%a,a) + return (g,x-(b/a)*y,y) + def modinv(a,m): + g,x,y = egcd(a,m) + if g != 1: + raise Expection("[-] Sorry") + else : + return x%m + + d = modinv(e,phi) + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = ") + print(output) + +except ValueError: + slowprint("\n[-] c,n,e,dp Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA8.py b/RSA8.py new file mode 100644 index 0000000..bd0deb8 --- /dev/null +++ b/RSA8.py @@ -0,0 +1,33 @@ +from banner import * +banner() + + + +# Example +#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 + +try: + import gmpy2 + import binascii + gmpy2.get_context().precision=99999999999999999 + c = int(raw_input(">>> c = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + m = gmpy2.iroot(c, 3)[0] + assert pow(m,3) == c + def hex_pair(x): + return ('0' * (len(x) % 2)) + x + m_hex = '{:x}'.format(m) + m_hex = hex_pair(m_hex) + msg = binascii.unhexlify(m_hex) + slowprint("[+] The PlainText = ") + print(msg.decode()) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py new file mode 100644 index 0000000..b9cb276 --- /dev/null +++ b/RSA_chinese_remainder_theorem.py @@ -0,0 +1,52 @@ +from banner import * +banner() +""" +#Example + +c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 +p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 +q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 +dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 +dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 +""" + + + + +try: + c = int(raw_input(">>> c = ")) + p = int(raw_input(">>> p = ")) + q = int(raw_input(">>> q = ")) + dp = int(raw_input(">>> dp = ")) + dp = int(raw_input(">>> dq = ")) + slowprint("\n[+] Please Wait ... \033[95m\n") + + def egcd(a,b): + if a == 0: + return (b, 0, 1) + else: + g, y, x = egcd(b % a, a) + return (g, x - (b / a) * y, y) + def modinv(a,m): + g, x, y = egcd(a, m) + if g != 1: + raise Exception('modular inverse does not exist') + else: + return x % m + def chinese_remainder_theorem(p,q,dp,dq,chipher_text): + q_inv = modinv(p , q) + m1 = pow(chipher_text,dp,p) + m2 = pow(chipher_text,dq,q) + h = (q_inv*(m1-m2)) % p + return m2 + h * q + decode = hex(chinese_remainder_theorem(p,q,dp,dq,c))[2:].replace('L','') + slowprint("[+] The PlainText = ") + print decode.decode("hex") +except ValueError: + slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py new file mode 100644 index 0000000..c2d5f80 --- /dev/null +++ b/RSA_common_modulus.py @@ -0,0 +1,54 @@ +from banner import * +banner() +try: + import gmpy2 + from Crypto.Util.number import * + def egcd(a, b): + if (a == 0): + return (b, 0, 1) + else: + g, y, x = egcd(b % a, a) + return (g, x - (b // a) * y, y) + + # Calculates a^{b} mod n when b is negative + def neg_pow(a, b, n): + assert b < 0 + assert GCD(a, n) == 1 + res = int(gmpy2.invert(a, n)) + res = pow(res, b*(-1), n) + return res + + + def common_modulus(e1, e2, n, c1, c2): + g, a, b = egcd(e1, e2) + if a < 0: + c1 = neg_pow(c1, a, n) + else: + c1 = pow(c1, a, n) + if b < 0: + c2 = neg_pow(c2, b, n) + else: + c2 = pow(c2, b, n) + ct = c1*c2 % n + m = int(gmpy2.iroot(ct, g)[0]) + return long_to_bytes(m) + + c1 = int(raw_input(">>> c1 = ")) + c2 = int(raw_input(">>> c2 = ")) + e1 = int(raw_input(">>> e1 = ")) + e2 = int(raw_input(">>> e2 = ")) + n = int(raw_input(">>> n = ")) + + slowprint("\n[+] Please Wait ... \033[95m\n") + slowprint("[+] The PlainText = ") + print common_modulus(e1, e2, n, c1, c2) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_hasted.py b/RSA_hasted.py new file mode 100644 index 0000000..f553868 --- /dev/null +++ b/RSA_hasted.py @@ -0,0 +1,79 @@ +from banner import * +banner() + +# N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 +# C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 +# N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 +# C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 +# N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 +# C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 + + + +def chinese_remainder(n, a): + sum = 0 + prod = functools.reduce(lambda a, b: a*b, n) + for n_i, a_i in zip(n, a): + p = prod // n_i + sum += a_i * mul_inv(p, n_i) * p + return sum % prod + +def mul_inv(a, b): + b0 = b + x0, x1 = 0, 1 + if b == 1: return 1 + while a > 1: + q = a // b + a, b = b, a%b + x0, x1 = x1 - q * x0, x0 + if x1 < 0: x1 += b0 + return x1 + +def inv_pow(c, e): + low = -1 + high = c+1 + while low + 1 < high: + m = (low + high) // 2 + p = pow(m, e) + if p < c: + low = m + else: + high = m + m = high + assert pow(m, e) == c + return m + + +try: + import functools + import itertools + + C1 = int(raw_input(">>> c1 = ")) + C2 = int(raw_input(">>> c2 = ")) + C3 = int(raw_input(">>> c3 = ")) + N1 = int(raw_input(">>> n1 = ")) + N2 = int(raw_input(">>> n2 = ")) + N3 = int(raw_input(">>> n3 = ")) + N = [N1, N2, N3] + C = [C1, C2, C3] + e = len(N) + print "e = ",e + slowprint("\n[+] Please Wait ... \033[95m\n") + + a = chinese_remainder(N, C) + for n, c in zip(N, C): + assert a % n == c + m = inv_pow(a, e) + decode = (hex(m)[2:]).replace('L','') + slowprint("[+] The PlainText = ") + print decode.decode("hex") +except ValueError: + slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except ImportError: + slowprint("\n[-] Module Not Setup") +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py new file mode 100644 index 0000000..1afa4c3 --- /dev/null +++ b/RSA_multiPrime1.py @@ -0,0 +1,55 @@ +from banner import * +banner() + +""" +c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 +n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 +e= 65537 +prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] +""" + +try: + from ecm import * + import binascii + c = int(raw_input(">>> c = ")) + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + slowprint("\n[+] Please Wait ... ") + prime = primefactors(n) + phi = 1 + for i in prime: + phi *= i-1 + def egcd(a, b): + if a == 0: + return (b, 0, 1) + g, y, x = egcd(b%a,a) + return (g, x - (b//a) * y, y) + def modinv(a, m): + g, x, y = egcd(a, m) + if g != 1: + raise Exception('No modular inverse') + return x%m + d = modinv(e, phi) + m = pow(c, d, n) + def hex_pair(x): + return ('0' * (len(x) % 2)) + x + m_hex = '{:x}'.format(m) + m_hex = hex_pair(m_hex) + msg = binascii.unhexlify(m_hex) + slowprint("\n[+] The PlainText = ") + print(msg.decode(errors="ignore")) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,n,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except Exception: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("[-] False Attack !") diff --git a/RSA_wiener.py b/RSA_wiener.py new file mode 100644 index 0000000..63bc446 --- /dev/null +++ b/RSA_wiener.py @@ -0,0 +1,89 @@ +from banner import * +banner() + +#Example : +""" +n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 +c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 + +""" +try: + import random + n = int(raw_input(">>> n = ")) + e = int(raw_input(">>> e = ")) + + slowprint("\n[+] Please Wait ... \033[95m\n") + + def division_euclidienne(a, b): + return (a // b, a % b) + def fraction_continue(n, d): + developpement = [] + a = n + b = d + while b != 0: + (q,r) = division_euclidienne(a,b) + developpement.append(q) + a = b + b = r + return (developpement) + def reduites_fraction_continue(a): + l=len(a) + reduites=[] + h0 = 1 + h1 = 0 + k0 = 0 + k1 = 1 + count = 0 + while count < l: + h = a[count] * h1 + h0 + h0 = h1 + h1 = h + k = a[count] * k1 + k0 + k0 = k1 + k1 = k + reduites.append((k,h)) + count += 1 + return (reduites) + def wiener(n, e): + fc = fraction_continue(e, n) + reduites = reduites_fraction_continue(fc) + message_clair = random.randint(10**1,10**5) + message_chiffre = pow(message_clair, e, n) + l = len(reduites) + i = 0 + while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: + i += 1 + if i != l: + slowprint("[+] Getting d ... \033[95m\n") + return (reduites[i][1]) + else: + print("[-] Sorry it's Not Wiener Attack\n") + exit(0) + + d = wiener(n,e) + print "\nd = ",d + check = raw_input("\nYou Have Cipher [y/n] : ") + if check == "y" or check == "yes": + c = int(raw_input(">>> c = ")) + slowprint("[+] Getting PlainText ... \033[92m\n") + decode = pow(c,d,n) + output = (hex(decode)[2:].replace('L','')).decode("hex") + slowprint("[+] The PlainText = \033[92m") + print output + else : + slowprint("[+] Thanx For Using X-RSA \033[95m") + exit() + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except Exception: + slowprint("\n[-] Wrong Data") +except: + slowprint("\n[-] False Attack !") diff --git a/banner.py b/banner.py new file mode 100644 index 0000000..002739b --- /dev/null +++ b/banner.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python2 +#-*- coding: utf-8 -*- +# +# author : X-Vector +# Tested on Kali Linux / Parrot Os / Ubuntu +# Simple script for RSA Attack +import sys +import platform,os +from urllib2 import * +from platform import system +def slowprint(s): + for c in s + '\n': + sys.stdout.write(c) + sys.stdout.flush() + time.sleep(4. / 100) + +clear = "" +if "Windows" in platform.system(): + clear = "cls" +if "Linux" in platform.system(): + clear = "clear" +os.system(clear) +is_windows = sys.platform.startswith('win') + +# Console Colors +if is_windows: + # Windows deserves coloring too :D + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + try: + import win_unicode_console , colorama + win_unicode_console.enable() + colorama.init() + #Now the unicode will work ^_^ + except: + print("[!] Error: Coloring libraries not installed, no coloring will be used") + G = Y = B = R = W = G = Y = B = R = W = '' + + +else: + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + + +def banner(): + print("""%s +_____ ________________ _____ _____ +\ \ / /\ \ _____\ \ / |_ + \ | | / \ /\ \ / / \ | / \\ + \ \ / / | \_\ | | | /___/|| /\ \\ + \ | / | ___/ ____\ \ | ||| | | \\ + / | \ | \ ____ / /\ \|___|/| \/ \\ + / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ + |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ + | | | | | | | | || | || | | | | | | | + |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| + %s%s +[ Version : 0.3 ]\033[92m +[ Author : X-Vector ]\033[96m +[ Github : github.com/X-Vector ]\033[93m +[ Twitter : twitter.com/@XVector11 ]\033[95m +[ Facebook: facebook.com/X.Vector1 ]\033[95m +[ GreeteZ : Karem Ali ]\033[94m + """ % (R, W,R)) diff --git a/ecm.py b/ecm.py new file mode 100644 index 0000000..79d6ef8 --- /dev/null +++ b/ecm.py @@ -0,0 +1,135 @@ +import random + +def primesbelow(N): + # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 + # Input N>=6, Returns a list of primes, 2 <= p < N + correction = N % 6 > 1 + N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6] + sieve = [True] * (N // 3) + sieve[0] = False + for i in range(int(N ** .5) // 3 + 1): + if sieve[i]: + k = (3 * i + 1) | 1 + sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1) + sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1) + return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]] + +smallprimeset = set(primesbelow(100000)) +_smallprimeset = 100000 +def isprime(n, precision=7): + # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time + if n < 1: + raise ValueError("Out of bounds, first argument must be > 0") + elif n <= 3: + return n >= 2 + elif n % 2 == 0: + return False + elif n < _smallprimeset: + return n in smallprimeset + + + d = n - 1 + s = 0 + while d % 2 == 0: + d //= 2 + s += 1 + + for repeat in range(precision): + a = random.randrange(2, n - 2) + x = pow(a, d, n) + + if x == 1 or x == n - 1: continue + + for r in range(s - 1): + x = pow(x, 2, n) + if x == 1: return False + if x == n - 1: break + else: return False + + return True + +# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ +def pollard_brent(n): + if n % 2 == 0: return 2 + if n % 3 == 0: return 3 + + y, c, m = random.randint(1, n-1), random.randint(1, n-1), random.randint(1, n-1) + g, r, q = 1, 1, 1 + while g == 1: + x = y + for i in range(r): + y = (pow(y, 2, n) + c) % n + + k = 0 + while k < r and g==1: + ys = y + for i in range(min(m, r-k)): + y = (pow(y, 2, n) + c) % n + q = q * abs(x-y) % n + g = gcd(q, n) + k += m + r *= 2 + if g == n: + while True: + ys = (pow(ys, 2, n) + c) % n + g = gcd(abs(x - ys), n) + if g > 1: + break + + return g + +smallprimes = primesbelow(1000) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 +def primefactors(n, sort=False): + factors = [] + + for checker in smallprimes: + while n % checker == 0: + factors.append(checker) + n //= checker + if checker > n: break + + if n < 2: return factors + + while n > 1: + if isprime(n): + factors.append(n) + break + factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent + factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent + n //= factor + + if sort: factors.sort() + + return factors + +def factorization(n): + factors = {} + for p1 in primefactors(n): + try: + factors[p1] += 1 + except KeyError: + factors[p1] = 1 + return factors + +totients = {} +def totient(n): + if n == 0: return 1 + + try: return totients[n] + except KeyError: pass + + tot = 1 + for p, exp in factorization(n).items(): + tot *= (p - 1) * p ** (exp - 1) + + totients[n] = tot + return tot + +def gcd(a, b): + if a == b: return a + while b > 0: a, b = b, a % b + return a + +def lcm(a, b): + return abs((a // gcd(a, b)) * b) + diff --git a/factordb.py b/factordb.py new file mode 100644 index 0000000..affef52 --- /dev/null +++ b/factordb.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function, unicode_literals +import requests + + +ENDPOINT = "http://factordb.com/api" + + +class FactorDB(): + def __init__(self, n): + self.n = n + self.result = None + + def connect(self, reconnect=False): + if self.result and not reconnect: + return self.result + self.result = requests.get(ENDPOINT, params={"query": str(self.n)}) + return self.result + + def get_id(self): + if self.result: + return self.result.json().get("id") + return None + + def get_status(self): + if self.result: + return self.result.json().get("status") + return None + + def get_factor_from_api(self): + if self.result: + return self.result.json().get("factors") + return None + + def get_factor_list(self): + """ + get_factors: [['2', 3], ['3', 2]] + Returns: [2, 2, 2, 3, 3] + """ + factors = self.get_factor_from_api() + if not factors: + return [] + ml = [[int(x)] * y for x, y in factors] + return [y for x in ml for y in x] + diff --git a/fermat.py b/fermat.py new file mode 100644 index 0000000..2e85afe --- /dev/null +++ b/fermat.py @@ -0,0 +1,19 @@ +from gmpy2 import isqrt +from banner import * +def fermat(n): + a = isqrt(n) + b2 = a*a - n + b = isqrt(n) + while b*b != b2: + a = a + 1 + b2 = a*a - n + b = isqrt(b2) + if b > n : + print "\n%s[-] Sorry Can't Factorize Number%s"%(R,R) + exit() + p = a+b + q = a-b + print "%sp =%s"%(Y,G),p + print "%sq =%s"%(Y,G),q + + diff --git a/qs.py b/qs.py new file mode 100644 index 0000000..2127ab2 --- /dev/null +++ b/qs.py @@ -0,0 +1,788 @@ +from banner import * +banner() + + +from math import log,sqrt, ceil, floor +import random +from fractions import gcd +import sys +from builtins import ValueError + +MAX_DIGITS_POLLARD = 30 +POLLARD_QUICK_ITERATIONS = 20 +MIN_DIGITS_POLLARD_QUICK2 = 45 +POLLARD_QUICK2_ITERATIONS = 25 +SIQS_TRIAL_DIVISION_EPS = 25 +SIQS_MIN_PRIME_POLYNOMIAL = 400 +SIQS_MAX_PRIME_POLYNOMIAL = 4000 + +MILLER_RABIN_ITERATIONS = 50 + + +class Polynomial: + + def __init__(self, coeff=[], a=None, b=None): + self.coeff = coeff + self.a = a + self.b = b + + def eval(self, x): + res = 0 + for a in self.coeff[::-1]: + res *= x + res += a + return res + + +class FactorBasePrime: + + def __init__(self, p, tmem, lp): + self.p = p + self.soln1 = None + self.soln2 = None + self.tmem = tmem + self.lp = lp + self.ainv = None + + +def lowest_set_bit(a): + b = (a & -a) + low_bit = -1 + while (b): + b >>= 1 + low_bit += 1 + return low_bit + + +def to_bits(k): + + k_binary = bin(k)[2:] + return (bit == '1' for bit in k_binary[::-1]) + + +def pow_mod(a, k, m): + + r = 1 + b = a + for bit in to_bits(k): + if bit: + r = (r * b) % m + b = (b * b) % m + return r + + +def is_quadratic_residue(a, p): + return legendre(a, (p - 1) // 2, 1, p) == 1 + + +def legendre(a, q, l, n): + x = q ** l + if x == 0: + return 1 + + z = 1 + a %= n + + while x != 0: + if x % 2 == 0: + a = (a ** 2) % n + x //= 2 + else: + x -= 1 + z = (z * a) % n + return z + + +def sqrt_mod_prime(a, p): + # Algorithm from http://www.mersennewiki.org/index.php/Modular_Square_Root + assert a < p + assert is_probable_prime(p) + if a == 0: + return 0 + if p == 2: + return a + if p % 2 == 0: + return None + p_mod_8 = p % 8 + if p_mod_8 == 1: + # Shanks method + q = p // 8 + e = 3 + while q % 2 == 0: + q //= 2 + e += 1 + while True: + x = random.randint(2, p - 1) + z = pow_mod(x, q, p) + if pow_mod(z, 2 ** (e - 1), p) != 1: + break + y = z + r = e + x = pow_mod(a, (q - 1) // 2, p) + v = (a * x) % p + w = (v * x) % p + while True: + if w == 1: + return v + k = 1 + while pow_mod(w, 2 ** k, p) != 1: + k += 1 + d = pow_mod(y, 2 ** (r - k - 1), p) + y = (d ** 2) % p + r = k + v = (d * v) % p + w = (w * y) % p + elif p_mod_8 == 5: + v = pow_mod(2 * a, (p - 5) // 8, p) + i = (2 * a * v * v) % p + return (a * v * (i - 1)) % p + else: + return pow_mod(a, (p + 1) // 4, p) + + +def inv_mod(a, m): + return eea(a, m)[0] % m + + +def eea(a, b): + + if a == 0: + return (0, 1, b) + x = eea(b % a, a) + return (x[1] - b // a * x[0], x[0], x[2]) + + +def is_probable_prime(a): + + if a == 2: + return True + if a == 1 or a % 2 == 0: + return False + return primality_test_miller_rabin(a, MILLER_RABIN_ITERATIONS) + + +def primality_test_miller_rabin(a, iterations): + m = a - 1 + lb = lowest_set_bit(m) + m >>= lb + + for _ in range(iterations): + b = random.randint(2, a - 1) + j = 0 + z = pow_mod(b, m, a) + while not ((j == 0 and z == 1) or z == a - 1): + if (j > 0 and z == 1 or j + 1 == lb): + return False + j += 1 + z = (z * z) % a + + return True + + +def siqs_factor_base_primes(n, nf): + + global small_primes + factor_base = [] + for p in small_primes: + if is_quadratic_residue(n, p): + t = sqrt_mod_prime(n % p, p) + lp = round(log2(p)) + factor_base.append(FactorBasePrime(p, t, lp)) + if len(factor_base) >= nf: + break + return factor_base + + +def siqs_find_first_poly(n, m, factor_base): + + p_min_i = None + p_max_i = None + for i, fb in enumerate(factor_base): + if p_min_i is None and fb.p >= SIQS_MIN_PRIME_POLYNOMIAL: + p_min_i = i + if p_max_i is None and fb.p > SIQS_MAX_PRIME_POLYNOMIAL: + p_max_i = i - 1 + break + + # The following may happen if the factor base is small, make sure + # that we have enough primes. + if p_max_i is None: + p_max_i = len(factor_base) - 1 + if p_min_i is None or p_max_i - p_min_i < 20: + p_min_i = min(p_min_i, 5) + + target = sqrt(2 * float(n)) / m + target1 = target / ((factor_base[p_min_i].p + + factor_base[p_max_i].p) / 2) ** 0.5 + + # find q such that the product of factor_base[q_i] is approximately + # sqrt(2 * n) / m; try a few different sets to find a good one + best_q, best_a, best_ratio = None, None, None + for _ in range(30): + a = 1 + q = [] + + while a < target1: + p_i = 0 + while p_i == 0 or p_i in q: + p_i = random.randint(p_min_i, p_max_i) + p = factor_base[p_i].p + a *= p + q.append(p_i) + + ratio = a / target + + # ratio too small seems to be not good + if (best_ratio is None or (ratio >= 0.9 and ratio < best_ratio) or + best_ratio < 0.9 and ratio > best_ratio): + best_q = q + best_a = a + best_ratio = ratio + a = best_a + q = best_q + + s = len(q) + B = [] + for l in range(s): + fb_l = factor_base[q[l]] + q_l = fb_l.p + assert a % q_l == 0 + gamma = (fb_l.tmem * inv_mod(a // q_l, q_l)) % q_l + if gamma > q_l // 2: + gamma = q_l - gamma + B.append(a // q_l * gamma) + + b = sum(B) % a + b_orig = b + if (2 * b > a): + b = a - b + + assert 0 < b + assert 2 * b <= a + assert ((b * b - n) % a == 0) + + g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) + h = Polynomial([b, a]) + for fb in factor_base: + if a % fb.p != 0: + fb.ainv = inv_mod(a, fb.p) + fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p + fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p + + return g, h, B + + +def siqs_find_next_poly(n, factor_base, i, g, B): + + v = lowest_set_bit(i) + 1 + z = -1 if ceil(i / (2 ** v)) % 2 == 1 else 1 + b = (g.b + 2 * z * B[v - 1]) % g.a + a = g.a + b_orig = b + if (2 * b > a): + b = a - b + assert ((b * b - n) % a == 0) + + g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) + h = Polynomial([b, a]) + for fb in factor_base: + if a % fb.p != 0: + fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p + fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p + + return g, h + + +def siqs_sieve(factor_base, m): + sieve_array = [0] * (2 * m + 1) + for fb in factor_base: + if fb.soln1 is None: + continue + p = fb.p + i_start_1 = -((m + fb.soln1) // p) + a_start_1 = fb.soln1 + i_start_1 * p + lp = fb.lp + if p > 20: + for a in range(a_start_1 + m, 2 * m + 1, p): + sieve_array[a] += lp + + i_start_2 = -((m + fb.soln2) // p) + a_start_2 = fb.soln2 + i_start_2 * p + for a in range(a_start_2 + m, 2 * m + 1, p): + sieve_array[a] += lp + return sieve_array + + +def siqs_trial_divide(a, factor_base): + + divisors_idx = [] + for i, fb in enumerate(factor_base): + if a % fb.p == 0: + exp = 0 + while a % fb.p == 0: + a //= fb.p + exp += 1 + divisors_idx.append((i, exp)) + if a == 1: + return divisors_idx + return None + + +def siqs_trial_division(n, sieve_array, factor_base, smooth_relations, g, h, m, + req_relations): + + sqrt_n = sqrt(float(n)) + limit = log2(m * sqrt_n) - SIQS_TRIAL_DIVISION_EPS + for (i, sa) in enumerate(sieve_array): + if sa >= limit: + x = i - m + gx = g.eval(x) + divisors_idx = siqs_trial_divide(gx, factor_base) + if divisors_idx is not None: + u = h.eval(x) + v = gx + assert (u * u) % n == v % n + smooth_relations.append((u, v, divisors_idx)) + if (len(smooth_relations) >= req_relations): + return True + return False + + +def siqs_build_matrix(factor_base, smooth_relations): + fb = len(factor_base) + M = [] + for sr in smooth_relations: + mi = [0] * fb + for j, exp in sr[2]: + mi[j] = exp % 2 + M.append(mi) + return M + + +def siqs_build_matrix_opt(M): + + m = len(M[0]) + cols_binary = [""] * m + for mi in M: + for j, mij in enumerate(mi): + cols_binary[j] += "1" if mij else "0" + return [int(cols_bin[::-1], 2) for cols_bin in cols_binary], len(M), m + + +def add_column_opt(M_opt, tgt, src): + + M_opt[tgt] ^= M_opt[src] + + +def find_pivot_column_opt(M_opt, j): + + if M_opt[j] == 0: + return None + return lowest_set_bit(M_opt[j]) + + +def siqs_solve_matrix_opt(M_opt, n, m): + + row_is_marked = [False] * n + pivots = [-1] * m + for j in range(m): + i = find_pivot_column_opt(M_opt, j) + if i is not None: + pivots[j] = i + row_is_marked[i] = True + for k in range(m): + if k != j and (M_opt[k] >> i) & 1: # test M[i][k] == 1 + add_column_opt(M_opt, k, j) + perf_squares = [] + for i in range(n): + if not row_is_marked[i]: + perfect_sq_indices = [i] + for j in range(m): + if (M_opt[j] >> i) & 1: # test M[i][j] == 1 + perfect_sq_indices.append(pivots[j]) + perf_squares.append(perfect_sq_indices) + return perf_squares + + +def siqs_calc_sqrts(square_indices, smooth_relations): + + res = [1, 1] + for idx in square_indices: + res[0] *= smooth_relations[idx][0] + res[1] *= smooth_relations[idx][1] + res[1] = sqrt_int(res[1]) + return res + + +def sqrt_int(n): + + a = n + s = 0 + o = 1 << (int(log(n,2)) & ~1) + while o != 0: + t = s + o + if a >= t: + a -= t + s = (s >> 1) + o + else: + s >>= 1 + o >>= 2 + assert s * s == n + return s + + +def kth_root_int(n, k): + + u = n + s = n + 1 + while u < s: + s = u + t = (k - 1) * s + n // pow(s, k - 1) + u = t // k + return s + + +def siqs_factor_from_square(n, square_indices, smooth_relations): + sqrt1, sqrt2 = siqs_calc_sqrts(square_indices, smooth_relations) + assert (sqrt1 * sqrt1) % n == (sqrt2 * sqrt2) % n + return gcd(abs(sqrt1 - sqrt2), n) + + +def siqs_find_factors(n, perfect_squares, smooth_relations): + + factors = [] + rem = n + non_prime_factors = set() + prime_factors = set() + for square_indices in perfect_squares: + fact = siqs_factor_from_square(n, square_indices, smooth_relations) + if fact != 1 and fact != rem: + if is_probable_prime(fact): + if fact not in prime_factors: + prime_factors.add(fact) + + while rem % fact == 0: + factors.append(fact) + rem //= fact + + if rem == 1: + break + if is_probable_prime(rem): + factors.append(rem) + rem = 1 + break + else: + if fact not in non_prime_factors: + non_prime_factors.add(fact) + + if rem != 1 and non_prime_factors: + non_prime_factors.add(rem) + for fact in sorted(siqs_find_more_factors_gcd(non_prime_factors)): + while fact != 1 and rem % fact == 0: + factors.append(fact) + rem //= fact + if rem == 1 or is_probable_prime(rem): + break + + if rem != 1: + factors.append(rem) + return factors + + +def siqs_find_more_factors_gcd(numbers): + res = set() + for n in numbers: + res.add(n) + for m in numbers: + if n != m: + fact = gcd(n, m) + if fact != 1 and fact != n and fact != m: + if fact not in res: + res.add(fact) + res.add(n // fact) + res.add(m // fact) + return res + + +def siqs_choose_nf_m(d): + # Using similar parameters as msieve-1.52 + if d <= 34: + return 200, 65536 + if d <= 36: + return 300, 65536 + if d <= 38: + return 400, 65536 + if d <= 40: + return 500, 65536 + if d <= 42: + return 600, 65536 + if d <= 44: + return 700, 65536 + if d <= 48: + return 1000, 65536 + if d <= 52: + return 1200, 65536 + if d <= 56: + return 2000, 65536 * 3 + if d <= 60: + return 4000, 65536 * 3 + if d <= 66: + return 6000, 65536 * 3 + if d <= 74: + return 10000, 65536 * 3 + if d <= 80: + return 30000, 65536 * 3 + if d <= 88: + return 50000, 65536 * 3 + if d <= 94: + return 60000, 65536 * 9 + return 100000, 65536 * 9 + + +def siqs_factorise(n): + + dig = len(str(n)) + nf, m = siqs_choose_nf_m(dig) + + factor_base = siqs_factor_base_primes(n, nf) + + required_relations_ratio = 1.05 + success = False + smooth_relations = [] + prev_cnt = 0 + i_poly = 0 + while not success: + required_relations = round(len(factor_base) * required_relations_ratio) + enough_relations = False + while not enough_relations: + if i_poly == 0: + g, h, B = siqs_find_first_poly(n, m, factor_base) + else: + g, h = siqs_find_next_poly(n, factor_base, i_poly, g, B) + i_poly += 1 + if i_poly >= 2 ** (len(B) - 1): + i_poly = 0 + sieve_array = siqs_sieve(factor_base, m) + enough_relations = siqs_trial_division( + n, sieve_array, factor_base, smooth_relations, + g, h, m, required_relations) + + if (len(smooth_relations) >= required_relations or + i_poly % 8 == 0 and len(smooth_relations) > prev_cnt): + + prev_cnt = len(smooth_relations) + + + M = siqs_build_matrix(factor_base, smooth_relations) + M_opt, M_n, M_m = siqs_build_matrix_opt(M) + + + perfect_squares = siqs_solve_matrix_opt(M_opt, M_n, M_m) + + + factors = siqs_find_factors(n, perfect_squares, smooth_relations) + if len(factors) > 1: + success = True + else: + required_relations_ratio += 0.05 + + return factors + + +def check_factor(n, i, factors): + while n % i == 0: + n //= i + factors.append(i) + if is_probable_prime(n): + factors.append(n) + n = 1 + return n + + +def trial_div_init_primes(n, upper_bound): + global small_primes + is_prime = [True] * (upper_bound + 1) + is_prime[0:2] = [False] * 2 + factors = [] + small_primes = [] + max_i = sqrt_int(upper_bound) + rem = n + for i in range(2, max_i + 1): + if is_prime[i]: + small_primes.append(i) + rem = check_factor(rem, i, factors) + if rem == 1: + return factors, 1 + + for j in (range(i ** 2, upper_bound + 1, i)): + is_prime[j] = False + + for i in range(max_i + 1, upper_bound + 1): + if is_prime[i]: + small_primes.append(i) + rem = check_factor(rem, i, factors) + if rem == 1: + return factors, 1 + return factors, rem + + +def pollard_brent_f(c, n, x): + x1 = (x * x) % n + c + if x1 >= n: + x1 -= n + assert x1 >= 0 and x1 < n + return x1 + + +def pollard_brent_find_factor(n, max_iter=None): + + y, c, m = (random.randint(1, n - 1) for _ in range(3)) + r, q, g = 1, 1, 1 + i = 0 + while g == 1: + x = y + for _ in range(r): + y = pollard_brent_f(c, n, y) + k = 0 + while k < r and g == 1: + ys = y + for _ in range(min(m, r - k)): + y = pollard_brent_f(c, n, y) + q = (q * abs(x - y)) % n + g = gcd(q, n) + k += m + r *= 2 + if max_iter: + i += 1 + if (i == max_iter): + return None + + if g == n: + while True: + ys = pollard_brent_f(c, n, ys) + g = gcd(abs(x - ys), n) + if g > 1: + break + return g + + +def pollard_brent_quick(n, factors): + + rem = n + while True: + if is_probable_prime(rem): + factors.append(rem) + rem = 1 + break + + digits = len(str(n)) + if digits < MIN_DIGITS_POLLARD_QUICK2: + max_iter = POLLARD_QUICK_ITERATIONS + else: + max_iter = POLLARD_QUICK2_ITERATIONS + + f = pollard_brent_find_factor(rem, max_iter) + if f and f < rem: + if is_probable_prime(f): + factors.append(f) + assert rem % f == 0 + rem //= f + else: + rem_f = pollard_brent_quick(f, factors) + rem = (rem // f) * rem_f + else: + break + return rem + + +def check_perfect_power(n): + largest_checked_prime = small_primes[-1] + for b in small_primes: + bth_root = kth_root_int(n, b) + if bth_root < largest_checked_prime: + break + if (bth_root ** b == n): + return (bth_root, b) + return None + + +def find_prime_factors(n): + perfect_power = check_perfect_power(n) + if perfect_power: + factors = [perfect_power[0]] + else: + digits = len(str(n)) + if digits <= MAX_DIGITS_POLLARD: + factors = [pollard_brent_find_factor(n)] + else: + factors = siqs_factorise(n) + + prime_factors = [] + for f in set(factors): + for pf in find_all_prime_factors(f): + prime_factors.append(pf) + + return prime_factors + + +def find_all_prime_factors(n): + rem = n + factors = [] + + while rem > 1: + if is_probable_prime(rem): + factors.append(rem) + break + + for f in find_prime_factors(rem): + assert is_probable_prime(f) + assert rem % f == 0 + while rem % f == 0: + rem //= f + factors.append(f) + + return factors + + +def product(factors): + prod = 1 + for f in factors: + prod *= f + return prod + + +def factorise(n): + + if type(n) is long: + return "Long" + if type(n) != int or n < 1: + return False + + if n == 1: + return [] + + if is_probable_prime(n): + return [n] + + factors, rem = trial_div_init_primes(n, 1000000) + + if factors: + pass + else: + if rem != 1: + digits = len(str(rem)) + if digits > MAX_DIGITS_POLLARD: + rem = pollard_brent_quick(rem, factors) + if rem > 1: + for fr in find_all_prime_factors(rem): + factors.append(fr) + + factors.sort() + assert product(factors) == n + for p in factors: + assert is_probable_prime(p) + return factors + + + + From 7e60daad500ea91d4815637a6776813713b5432e Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:44:14 +0200 Subject: [PATCH 057/122] Update README.md --- README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 21d5a8c..75937f8 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ # X-RSA -- X-RSA V0.2 contains a many of attack types such as Hasted, Fermat, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attack. -- New Attack Added To X-RSA V0.2 And Fixing Many Error in V0.1 +**What's X-RSA ?** +- X-RSA contains a many of attack types such as Hasted, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attack. -- X-RSA helps you in [CTF, Hacking , Penetration Testing , Decryption] +**What's New in X-RSA ?** +- Added [New Attacks , Factorization Method ] To X-RSA V0.3 And Fixing Many Error in V0.2 + +**Why X-RSA ?** +- X-RSA help you in [CTF, Hacking , Penetration Testing , Decryption] + +- Written By [ Python 2.7 ] -- Written By [Python] # Installing and Open Tool 1 - install tool @@ -21,9 +26,18 @@ pip install -r requirement.txt ``` python Attack.py ``` -# Screenshots +# Screenshots +**1 - X-RSA** +![X-RSA](https://2.top4top.net/p_1265rgruu1.png) -![X-RSA](https://e.top4top.net/p_1196pglz71.png "X-RSA in Action") +**2 - X-RSA Attackes** +![X-RSA](https://3.top4top.net/p_1265d35pz2.png) + +**3 - X-RSA Factorization** +![X-RSA](https://4.top4top.net/p_12653eztj3.png) - Coded By X-Vector - [Facebook](https://www.facebook.com/X.Vector1) - [Linkedin](https://www.linkedin.com/in/x-vector/) - [Twitter](https://twitter.com/@XVector11) + +# Reference +- [Quadratic sieve](https://github.com/skollmann/PyFactorise) From cdb792405c9511a4cb73f2fdabd5610d585a8211 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 12:51:55 +0200 Subject: [PATCH 058/122] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 75937f8..28422f3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # X-RSA **What's X-RSA ?** -- X-RSA contains a many of attack types such as Hasted, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attack. +- it's a Tool Which contains a many of attack types in RSA such as Hasted, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attacks. **What's New in X-RSA ?** -- Added [New Attacks , Factorization Method ] To X-RSA V0.3 And Fixing Many Error in V0.2 +- Added [ New Attacks , Factorization Methods ] To X-RSA V0.3 And Fixing Many Error in V0.2 **Why X-RSA ?** - X-RSA help you in [CTF, Hacking , Penetration Testing , Decryption] @@ -12,8 +12,8 @@ - Written By [ Python 2.7 ] -# Installing and Open Tool -1 - install tool +# Installing and Running Tool +1 - Install Tool ``` git clone https://github.com/X-Vector/X-RSA.git ``` @@ -22,7 +22,7 @@ git clone https://github.com/X-Vector/X-RSA.git apt install libgmp-dev libmpfr-dev libmpc-dev pip install -r requirement.txt ``` -3 - Open Tool +3 - Run Tool ``` python Attack.py ``` From a95f71f9caf23c9e99cd632ac623e47dfca4c607 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 13:13:56 +0200 Subject: [PATCH 059/122] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28422f3..ea1d757 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - Added [ New Attacks , Factorization Methods ] To X-RSA V0.3 And Fixing Many Error in V0.2 **Why X-RSA ?** -- X-RSA help you in [CTF, Hacking , Penetration Testing , Decryption] +- X-RSA help you in [CTF , Penetration Testing , Decryption] - Written By [ Python 2.7 ] From 33eb924db5f565725e1b0085129f6749513c8117 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 19 Jun 2019 14:10:26 +0200 Subject: [PATCH 060/122] Update requirement.txt --- requirement.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirement.txt b/requirement.txt index eb39d22..54fa500 100644 --- a/requirement.txt +++ b/requirement.txt @@ -1,6 +1,5 @@ Crypto gmpy2 gmpy -PyCrypto SymPy requests From eeb894a1cc143b282b0c9e9450560e1f059bd1fc Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Thu, 20 Jun 2019 19:19:47 +0200 Subject: [PATCH 061/122] Update Factorization.py --- Factorization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Factorization.py b/Factorization.py index e298bf5..42bfa54 100644 --- a/Factorization.py +++ b/Factorization.py @@ -8,7 +8,7 @@ print(""" [1] - Factordb Factorization \033[92m -[2] - Fermet Factorization \033[96m +[2] - Fermat Factorization \033[96m [3] - ECM Factorization \033[93m [4] - Quadratic sieve Factorization \033[95m [0] - Exit \033[92m From f596c0c43d68b8eedc4746c447389d69cb4f8e75 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sun, 30 Jun 2019 22:15:01 +0200 Subject: [PATCH 062/122] Update Attack.py --- Attack.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Attack.py b/Attack.py index ff91887..f5b5cc2 100644 --- a/Attack.py +++ b/Attack.py @@ -24,6 +24,7 @@ [11] - Attack(c,d,n,e)\033[92m [12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] [13] - Attack(c,e = 3)\033[0m +[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Exponent ] [0] - Exit \033[92m """) x = int(raw_input(">>> ")) @@ -66,6 +67,9 @@ elif x == 13: os.system(clear) import RSA8 + elif x == 14: + os.system(clear) + import RSA_common_exponent else: exit() else: From f98d19207e3760b2d1c0316b1d6df2389a1d5a01 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sun, 30 Jun 2019 22:15:21 +0200 Subject: [PATCH 063/122] Add files via upload --- RSA_common_exponent.py | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 RSA_common_exponent.py diff --git a/RSA_common_exponent.py b/RSA_common_exponent.py new file mode 100644 index 0000000..c6aa4ff --- /dev/null +++ b/RSA_common_exponent.py @@ -0,0 +1,50 @@ +from banner import * +banner() +import gmpy +def egcd(a, b): + if (a == 0): + return (b, 0, 1) + else: + g, y, x = egcd(b % a, a) + return (g, x - (b // a) * y, y) + +""" +n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 +n2 = 1210032872259313686164929473710869592253665432474968016181665104415833992599841926829524498430031021642288824945683044264288937821741278527156550423507713336648261819557381748119064650541556448192793186877429032749223390372405186620392499684387407129200331654256366265932387530132500098451224874600895892420947291972547271991706165603868937708772321221206586800972518013238899316242083977031307714803896630612616326248775444788388309984437812243115218989690016673 +c1 = 66392227979404854586458510145632770314092785183583016343730600866783415262123689751268136986554015242755982639115194608534311988971825645169411730748186710947220673034519486951708550346274786041388143262608730637962604985755406789741345581700390500478433427709495522821473858104289236940045533583368435030007 +c2 = 930631363282343082351877158963544600758567980445720982159124066613164772521801283854718425072511342860751113498013426077785323580215340717638119847338418916957048868138332980175665931485108461262077829550248080371766930777925758187526884947593887945397880426339790518082874861594313920319799945895788141894706108889222173060684161230756671422619830375801046671640406258873119163443168478229210037764301299889548125261094599251838443625348832760001827881979679672 +e = 65537 +""" + + +n1 = int(raw_input(">>> n1 = ")) +n2 = int(raw_input(">>> n2 = ")) +c1 = int(raw_input(">>> c1 = ")) +c2 = int(raw_input(">>> c2 = ")) +e = int(raw_input(">>> e = ")) + +if egcd(n1,n2)[0] == 1: + print "[-] Can't Factorize N" + exit() +else: + p = egcd(n1,n2)[0] + q1 = n1 / p + q2 = n2 / p + phi1 = (p-1) * (q1 - 1) + phi2 = (p-1) * (q2 - 1) + d1 = gmpy.invert(e,phi1) + d2 = gmpy.invert(e,phi2) + try: + m1 = hex(pow(c1,d1,n1)).replace("0x","").replace("L","").decode("hex") + slowprint("%s[+] The PlainText = "%(R)) + print "%s"%(G),m1 + except TypeError: + pass + + try: + m2 = hex(pow(c2,d2,n2)).replace("0x","").replace("L","").decode("hex") + slowprint("%s[+] The PlainText = "%(R)) + print "%s"%(G),m2 + except TypeError: + pass + From f0cacf140fec79934a640414882c83970d1855c6 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sun, 30 Jun 2019 22:18:32 +0200 Subject: [PATCH 064/122] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea1d757..8332b9d 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ python Attack.py ![X-RSA](https://2.top4top.net/p_1265rgruu1.png) **2 - X-RSA Attackes** -![X-RSA](https://3.top4top.net/p_1265d35pz2.png) +![X-RSA](https://3.top4top.net/p_1276y88c71.png) **3 - X-RSA Factorization** -![X-RSA](https://4.top4top.net/p_12653eztj3.png) +![X-RSA](https://1.top4top.net/p_1276dxpcy1.png) - Coded By X-Vector - [Facebook](https://www.facebook.com/X.Vector1) - [Linkedin](https://www.linkedin.com/in/x-vector/) - [Twitter](https://twitter.com/@XVector11) From 15ebcce92a4d0c321754b015955f5d0776d8977e Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:34:19 +0200 Subject: [PATCH 065/122] Update Attack.py --- Attack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Attack.py b/Attack.py index f5b5cc2..3a07344 100644 --- a/Attack.py +++ b/Attack.py @@ -24,7 +24,7 @@ [11] - Attack(c,d,n,e)\033[92m [12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] [13] - Attack(c,e = 3)\033[0m -[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Exponent ] +[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Factor ] [0] - Exit \033[92m """) x = int(raw_input(">>> ")) From ce02c372473ecf03d3c262b2282c4514f17e10e9 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:35:06 +0200 Subject: [PATCH 066/122] Update RSA.py --- RSA.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA.py b/RSA.py index 83d7520..2473950 100644 --- a/RSA.py +++ b/RSA.py @@ -23,12 +23,13 @@ def factordb(n): q = factordb[0] p = factordb[1] phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) def modinv(a,m): g,x,y = egcd(a,m) From 54b9859ae43e81954dbf29f4f03f3e8a1a1db33f Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:35:48 +0200 Subject: [PATCH 067/122] Update RSA6.py --- RSA6.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA6.py b/RSA6.py index d8d78ff..e8c9b4f 100644 --- a/RSA6.py +++ b/RSA6.py @@ -17,12 +17,13 @@ slowprint("\n[+] Please Wait ... \033[95m\n") q = n/p phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) def modinv(a,m): g,x,y = egcd(a,m) if g != 1: From 4a3ddbd4b154649fff2136db92aa9870188d29b3 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:36:00 +0200 Subject: [PATCH 068/122] Update RSA7.py --- RSA7.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA7.py b/RSA7.py index cb69a64..5d0e51e 100644 --- a/RSA7.py +++ b/RSA7.py @@ -23,12 +23,13 @@ q = n/p slowprint("\n[+] Please Wait ... \033[95m\n") phi = (p-1)*(q-1) - def egcd(a,b): - if a == 0 : - return(b,0,1) - else: - g,y,x = egcd(b%a,a) - return (g,x-(b/a)*y,y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) def modinv(a,m): g,x,y = egcd(a,m) if g != 1: From be16cb0d045b84d24124f94c8fe5002971d0a7dc Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:36:17 +0200 Subject: [PATCH 069/122] Update RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py index b9cb276..99ae771 100644 --- a/RSA_chinese_remainder_theorem.py +++ b/RSA_chinese_remainder_theorem.py @@ -21,12 +21,13 @@ dp = int(raw_input(">>> dq = ")) slowprint("\n[+] Please Wait ... \033[95m\n") - def egcd(a,b): - if a == 0: - return (b, 0, 1) - else: - g, y, x = egcd(b % a, a) - return (g, x - (b / a) * y, y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) def modinv(a,m): g, x, y = egcd(a, m) if g != 1: From 00434981c07abdcd168c2cc338cf4f963a50bbd3 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:36:34 +0200 Subject: [PATCH 070/122] Update RSA_common_modulus.py --- RSA_common_modulus.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py index c2d5f80..bc6ef12 100644 --- a/RSA_common_modulus.py +++ b/RSA_common_modulus.py @@ -3,12 +3,13 @@ try: import gmpy2 from Crypto.Util.number import * - def egcd(a, b): - if (a == 0): - return (b, 0, 1) - else: - g, y, x = egcd(b % a, a) - return (g, x - (b // a) * y, y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) # Calculates a^{b} mod n when b is negative def neg_pow(a, b, n): From 6b47d7cf213bec970bc1467e2107cf18e6169da6 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:36:48 +0200 Subject: [PATCH 071/122] Update RSA_multiPrime1.py --- RSA_multiPrime1.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py index 1afa4c3..3daabcc 100644 --- a/RSA_multiPrime1.py +++ b/RSA_multiPrime1.py @@ -19,11 +19,13 @@ phi = 1 for i in prime: phi *= i-1 - def egcd(a, b): - if a == 0: - return (b, 0, 1) - g, y, x = egcd(b%a,a) - return (g, x - (b//a) * y, y) + def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) def modinv(a, m): g, x, y = egcd(a, m) if g != 1: From aa324046f52c4f3c2ebccb2413c47be12951b158 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:38:32 +0200 Subject: [PATCH 072/122] Update RSA_common_exponent.py --- RSA_common_exponent.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/RSA_common_exponent.py b/RSA_common_exponent.py index c6aa4ff..dc87b2b 100644 --- a/RSA_common_exponent.py +++ b/RSA_common_exponent.py @@ -1,12 +1,13 @@ from banner import * banner() import gmpy -def egcd(a, b): - if (a == 0): - return (b, 0, 1) - else: - g, y, x = egcd(b % a, a) - return (g, x - (b // a) * y, y) +def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) """ n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 From a543cb6678be70d9c31b7b0186d3337966713418 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Sat, 19 Oct 2019 17:44:40 +0200 Subject: [PATCH 073/122] Update requirement.txt --- requirement.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirement.txt b/requirement.txt index 54fa500..26ce7c1 100644 --- a/requirement.txt +++ b/requirement.txt @@ -3,3 +3,4 @@ gmpy2 gmpy SymPy requests +future From fe837a99cbe3174de099d9002d8606554f3d43f1 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:35:29 +0200 Subject: [PATCH 074/122] Delete Attack.py --- Attack.py | 76 ------------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 Attack.py diff --git a/Attack.py b/Attack.py deleted file mode 100644 index 3a07344..0000000 --- a/Attack.py +++ /dev/null @@ -1,76 +0,0 @@ -from banner import * -banner() -print(""" -[1] - Attacks -[2] - Factorization Number -""") -check = int(raw_input(">>> ")) -if check == 2: - import Factorization - -elif check == 1: - banner() - print(""" -[1] - Attack(c,n,e) \033[92m -[2] - Attack(c,p,q,e) \033[96m -[3] - Attack (c,n,e,{p or q}) -[4] - Attack (c,n,e,dp) -[5] - Attack(c,n,d,e,phi) \033[93m -[6] - Attack(c1,c2,c3,n1,n2,n3,e=3) \033[95m [ Hasted ] -[7] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] -[8] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] -[9] - Attack(n,e) \033[95m [ Wiener ] -[10] - Attack(c,n,d)\033[0m -[11] - Attack(c,d,n,e)\033[92m -[12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] -[13] - Attack(c,e = 3)\033[0m -[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Factor ] -[0] - Exit \033[92m - """) - x = int(raw_input(">>> ")) - if x == 1: - os.system(clear) - import RSA - elif x == 2: - os.system(clear) - import RSA2 - elif x == 3: - os.system(clear) - import RSA6 - elif x == 4: - os.system(clear) - import RSA7 - elif x == 5: - os.system(clear) - import RSA3 - elif x == 6: - os.system(clear) - import RSA_hasted - elif x == 7: - os.system(clear) - import RSA_common_modulus - elif x == 8: - os.system(clear) - import RSA_chinese_remainder_theorem - elif x == 9: - os.system(clear) - import RSA_wiener - elif x == 10: - os.system(clear) - import RSA4 - elif x == 11: - os.system(clear) - import RSA5 - elif x == 12: - os.system(clear) - import RSA_multiPrime1 - elif x == 13: - os.system(clear) - import RSA8 - elif x == 14: - os.system(clear) - import RSA_common_exponent - else: - exit() -else: - exit() From 4150b164e62642c6ed8bc193511b8d8896a62dd7 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:35:32 +0200 Subject: [PATCH 075/122] Delete Factorization.py --- Factorization.py | 53 ------------------------------------------------ 1 file changed, 53 deletions(-) delete mode 100644 Factorization.py diff --git a/Factorization.py b/Factorization.py deleted file mode 100644 index 42bfa54..0000000 --- a/Factorization.py +++ /dev/null @@ -1,53 +0,0 @@ -from banner import * -banner() - -from factordb import * -from fermat import * -from ecm import * -from qs import * - -print(""" -[1] - Factordb Factorization \033[92m -[2] - Fermat Factorization \033[96m -[3] - ECM Factorization \033[93m -[4] - Quadratic sieve Factorization \033[95m -[0] - Exit \033[92m - """) - -x = int(raw_input(">>> ")) -#Factordb -if x == 1: - - n = int(raw_input("%s\nn = %s"%(B,B))) - print "\n[+] Please Wait ...\n" - def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - - print "%sprimes =%s"%(Y,Y),"%s"%(G),factordb(n) - -#Fermet -elif x == 2: - n = int(raw_input("%s\nn = %s"%(B,B))) - print "\n[+] Please Wait ...\n" - fermat(n) - -#ECM -elif x == 3: - n = int(raw_input("%s\nn = %s"%(B,B))) - print "\n[+] Please Wait ...\n" - print "%sprimes =%s"%(Y,Y),"%s"%(G),primefactors(n) - -elif x == 4: - N = int(raw_input("%s\nn = %s"%(B,B))) - if not factorise(N): - print("Number Must Be Greater Than 0 and Must Be Integer") - elif factorise(N) == "Long": - print("N is Too Long ") - else: - print "\n[+] Please Wait ...\n" - print "%sprimes =%s"%(Y,Y),"%s"%(G),factorise(N) - -else: - exit() From 2e6d7d6773c79de606e7fe369227c41c357ccbad Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:35:50 +0200 Subject: [PATCH 076/122] Delete RSA.py --- RSA.py | 59 ---------------------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 RSA.py diff --git a/RSA.py b/RSA.py deleted file mode 100644 index 2473950..0000000 --- a/RSA.py +++ /dev/null @@ -1,59 +0,0 @@ -from banner import * -banner() - -# Example : -#c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 -#n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 -#e = 65537 - -try: - import binascii - import gmpy2 - from factordb import * - def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - factordb = factordb(n) - q = factordb[0] - p = factordb[1] - phi = (p-1)*(q-1) - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("RSA Hello") - else : - return x%m - - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n :( ") - slowprint("\n[!] Try To Use MultiPrime Attack ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c, e, n Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From a5c9b543154ebef1657d308e84629f6609c0bd47 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:35:54 +0200 Subject: [PATCH 077/122] Delete RSA2.py --- RSA2.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 RSA2.py diff --git a/RSA2.py b/RSA2.py deleted file mode 100644 index 1aa823a..0000000 --- a/RSA2.py +++ /dev/null @@ -1,35 +0,0 @@ -from banner import * -banner() - - -#c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 -#p = 238324208831434331628131715304428889871 -#q = 296805874594538235115008173244022912163 -#e = 3 - - -try: - import gmpy - c = int(raw_input(">>> c = ")) - p = int(raw_input(">>> p = ")) - q = int(raw_input(">>> q = ")) - e = int(raw_input(">>> e = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - n = p*q - phi = (p-1)*(q-1) - d = gmpy.invert(e,phi) - m = hex(pow(c,d,n))[2:] - decode = m.decode('hex') - slowprint("[+] The PlainText = ") - print(decode) - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 622b4b1b7f956720a62419754e13b03725f50059 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:10 +0200 Subject: [PATCH 078/122] Delete RSA3.py --- RSA3.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 RSA3.py diff --git a/RSA3.py b/RSA3.py deleted file mode 100644 index a9fc6eb..0000000 --- a/RSA3.py +++ /dev/null @@ -1,30 +0,0 @@ -from banner import * -banner() - - -#c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 -#n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 -#d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 -#e = 65537 -#phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - d = int(raw_input(">>> d = ")) - e = int(raw_input(">>> e = ")) - phi = int(raw_input(">>> phi = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - n = hex(pow(c,d,n))[2:] - decode = (n.replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print decode -except ValueError: - slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From e54622efa2912452361a134a5424db9f0405a13a Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:12 +0200 Subject: [PATCH 079/122] Delete RSA4.py --- RSA4.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 RSA4.py diff --git a/RSA4.py b/RSA4.py deleted file mode 100644 index 381617d..0000000 --- a/RSA4.py +++ /dev/null @@ -1,27 +0,0 @@ -from banner import * -banner() - -#n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -#d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 -#c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 - - - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - d = int(raw_input(">>> d = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print output -except ValueError: - slowprint("\n[-] c,n,d Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From c838ab397c6a909be3c7fa734bd42231e99cd49c Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:36 +0200 Subject: [PATCH 080/122] Delete RSA5.py --- RSA5.py | 92 --------------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 RSA5.py diff --git a/RSA5.py b/RSA5.py deleted file mode 100644 index 3985d40..0000000 --- a/RSA5.py +++ /dev/null @@ -1,92 +0,0 @@ -from banner import * -banner() - -try: - from Crypto.PublicKey import RSA - import sympy as sp - import math -except ImportError: - slowprint("\n[-] Module Not Setup") -""" -#n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 -#e = 65537 -#d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 -#c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 -""" - -def premRSA(n,e,d,c): - bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) - bitLenD0 = 2048 - - assert bitLenD0 >= bitLenN/2 - - d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) - c = pow(c,d,n) - plaintext = str(bytearray(hex(c)[2:])).replace("L","") - slowprint("[+] The PlainText = ") - print(plaintext.decode("hex")) - -def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): - test = pow(3, e, n) - test2 = pow(5, e, n) - for k in range(1,e): - d = ((k * n + 1) // e) - d >>= d0BitSize - d <<= d0BitSize - d |= d0 - if((e * d) % k == 1): - if pow(test, d, n) == 3: - if pow(test2, d, n) == 5: - totientN = (e*d - 1) // k - b = totientN - n - 1 - discriminant = b*b - 4*n - root = floorSqrt(discriminant) - if(root*root != discriminant): - continue - p = (-b + root) // 2 - q = n // p - return d - - -def extended_gcd(aa, bb): - lastremainder, remainder = abs(aa), abs(bb) - x, lastx, y, lasty = 0, 1, 1, 0 - while remainder: - lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) - x, lastx = lastx - quotient*x, x - y, lasty = lasty - quotient*y, y - return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) - -def modinv(a, m): - g, x, y = extended_gcd(a, m) - if g != 1: - raise ValueError - return x % m - -def floorSqrt(n): - x = n - y = (x + 1) // 2 - while y < x: - x = y - y = (x + n // x) // 2 - return x - - - - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - d = int(raw_input(">>> d = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - premRSA(n,e,d,c) - -except ValueError: - slowprint("\n[-] c,n,d,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From ed797ab2c4b33c78d69ad5cd25049beaec0685cd Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:38 +0200 Subject: [PATCH 081/122] Delete RSA6.py --- RSA6.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 RSA6.py diff --git a/RSA6.py b/RSA6.py deleted file mode 100644 index e8c9b4f..0000000 --- a/RSA6.py +++ /dev/null @@ -1,46 +0,0 @@ -from banner import * -banner() - -import binascii - -""" -p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 -c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 -e = 65537 -n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 -""" -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - p = int(raw_input(">>> p = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - q = n/p - phi = (p-1)*(q-1) - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("RSA Hello") - else : - return x%m - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except ValueError: - slowprint("\n[-] c,n,e,p Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From f5ffc68ace2cbf456de539326329cf16b3e1fe95 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:40 +0200 Subject: [PATCH 082/122] Delete RSA7.py --- RSA7.py | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 RSA7.py diff --git a/RSA7.py b/RSA7.py deleted file mode 100644 index 5d0e51e..0000000 --- a/RSA7.py +++ /dev/null @@ -1,53 +0,0 @@ -from banner import * -banner() - -import binascii -""" -e = 65537 -n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 -dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 -c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 -""" - -try: - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - dp = int(raw_input(">>> dp = ")) - - mp = (dp * e) - 1 - for i in range(2,1000000): - p = (mp / i) + 1 - if n % p == 0: - break - q = n/p - slowprint("\n[+] Please Wait ... \033[95m\n") - phi = (p-1)*(q-1) - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - def modinv(a,m): - g,x,y = egcd(a,m) - if g != 1: - raise Expection("[-] Sorry") - else : - return x%m - - d = modinv(e,phi) - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = ") - print(output) - -except ValueError: - slowprint("\n[-] c,n,e,dp Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 4eb75551fed3ba7f8642b64857966e9a336785ea Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:43 +0200 Subject: [PATCH 083/122] Delete RSA8.py --- RSA8.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 RSA8.py diff --git a/RSA8.py b/RSA8.py deleted file mode 100644 index bd0deb8..0000000 --- a/RSA8.py +++ /dev/null @@ -1,33 +0,0 @@ -from banner import * -banner() - - - -# Example -#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 - -try: - import gmpy2 - import binascii - gmpy2.get_context().precision=99999999999999999 - c = int(raw_input(">>> c = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - m = gmpy2.iroot(c, 3)[0] - assert pow(m,3) == c - def hex_pair(x): - return ('0' * (len(x) % 2)) + x - m_hex = '{:x}'.format(m) - m_hex = hex_pair(m_hex) - msg = binascii.unhexlify(m_hex) - slowprint("[+] The PlainText = ") - print(msg.decode()) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 1ad0dee9d3104403042f758d796cad67749965bc Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:46 +0200 Subject: [PATCH 084/122] Delete RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 53 -------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 RSA_chinese_remainder_theorem.py diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py deleted file mode 100644 index 99ae771..0000000 --- a/RSA_chinese_remainder_theorem.py +++ /dev/null @@ -1,53 +0,0 @@ -from banner import * -banner() -""" -#Example - -c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 -p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 -q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 -dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 -dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 -""" - - - - -try: - c = int(raw_input(">>> c = ")) - p = int(raw_input(">>> p = ")) - q = int(raw_input(">>> q = ")) - dp = int(raw_input(">>> dp = ")) - dp = int(raw_input(">>> dq = ")) - slowprint("\n[+] Please Wait ... \033[95m\n") - - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - def modinv(a,m): - g, x, y = egcd(a, m) - if g != 1: - raise Exception('modular inverse does not exist') - else: - return x % m - def chinese_remainder_theorem(p,q,dp,dq,chipher_text): - q_inv = modinv(p , q) - m1 = pow(chipher_text,dp,p) - m2 = pow(chipher_text,dq,q) - h = (q_inv*(m1-m2)) % p - return m2 + h * q - decode = hex(chinese_remainder_theorem(p,q,dp,dq,c))[2:].replace('L','') - slowprint("[+] The PlainText = ") - print decode.decode("hex") -except ValueError: - slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From c16bab7d12ed108c8f76e18ac17d068a6ca7f914 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:49 +0200 Subject: [PATCH 085/122] Delete RSA_common_exponent.py --- RSA_common_exponent.py | 51 ------------------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 RSA_common_exponent.py diff --git a/RSA_common_exponent.py b/RSA_common_exponent.py deleted file mode 100644 index dc87b2b..0000000 --- a/RSA_common_exponent.py +++ /dev/null @@ -1,51 +0,0 @@ -from banner import * -banner() -import gmpy -def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - -""" -n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 -n2 = 1210032872259313686164929473710869592253665432474968016181665104415833992599841926829524498430031021642288824945683044264288937821741278527156550423507713336648261819557381748119064650541556448192793186877429032749223390372405186620392499684387407129200331654256366265932387530132500098451224874600895892420947291972547271991706165603868937708772321221206586800972518013238899316242083977031307714803896630612616326248775444788388309984437812243115218989690016673 -c1 = 66392227979404854586458510145632770314092785183583016343730600866783415262123689751268136986554015242755982639115194608534311988971825645169411730748186710947220673034519486951708550346274786041388143262608730637962604985755406789741345581700390500478433427709495522821473858104289236940045533583368435030007 -c2 = 930631363282343082351877158963544600758567980445720982159124066613164772521801283854718425072511342860751113498013426077785323580215340717638119847338418916957048868138332980175665931485108461262077829550248080371766930777925758187526884947593887945397880426339790518082874861594313920319799945895788141894706108889222173060684161230756671422619830375801046671640406258873119163443168478229210037764301299889548125261094599251838443625348832760001827881979679672 -e = 65537 -""" - - -n1 = int(raw_input(">>> n1 = ")) -n2 = int(raw_input(">>> n2 = ")) -c1 = int(raw_input(">>> c1 = ")) -c2 = int(raw_input(">>> c2 = ")) -e = int(raw_input(">>> e = ")) - -if egcd(n1,n2)[0] == 1: - print "[-] Can't Factorize N" - exit() -else: - p = egcd(n1,n2)[0] - q1 = n1 / p - q2 = n2 / p - phi1 = (p-1) * (q1 - 1) - phi2 = (p-1) * (q2 - 1) - d1 = gmpy.invert(e,phi1) - d2 = gmpy.invert(e,phi2) - try: - m1 = hex(pow(c1,d1,n1)).replace("0x","").replace("L","").decode("hex") - slowprint("%s[+] The PlainText = "%(R)) - print "%s"%(G),m1 - except TypeError: - pass - - try: - m2 = hex(pow(c2,d2,n2)).replace("0x","").replace("L","").decode("hex") - slowprint("%s[+] The PlainText = "%(R)) - print "%s"%(G),m2 - except TypeError: - pass - From bb8dc5abf2f3db43f4cd059f77a20101db0ff97e Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:51 +0200 Subject: [PATCH 086/122] Delete RSA_common_modulus.py --- RSA_common_modulus.py | 55 ------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 RSA_common_modulus.py diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py deleted file mode 100644 index bc6ef12..0000000 --- a/RSA_common_modulus.py +++ /dev/null @@ -1,55 +0,0 @@ -from banner import * -banner() -try: - import gmpy2 - from Crypto.Util.number import * - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - - # Calculates a^{b} mod n when b is negative - def neg_pow(a, b, n): - assert b < 0 - assert GCD(a, n) == 1 - res = int(gmpy2.invert(a, n)) - res = pow(res, b*(-1), n) - return res - - - def common_modulus(e1, e2, n, c1, c2): - g, a, b = egcd(e1, e2) - if a < 0: - c1 = neg_pow(c1, a, n) - else: - c1 = pow(c1, a, n) - if b < 0: - c2 = neg_pow(c2, b, n) - else: - c2 = pow(c2, b, n) - ct = c1*c2 % n - m = int(gmpy2.iroot(ct, g)[0]) - return long_to_bytes(m) - - c1 = int(raw_input(">>> c1 = ")) - c2 = int(raw_input(">>> c2 = ")) - e1 = int(raw_input(">>> e1 = ")) - e2 = int(raw_input(">>> e2 = ")) - n = int(raw_input(">>> n = ")) - - slowprint("\n[+] Please Wait ... \033[95m\n") - slowprint("[+] The PlainText = ") - print common_modulus(e1, e2, n, c1, c2) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From d3ab72b7dba66573a671d95376242736fdad4fe8 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:36:55 +0200 Subject: [PATCH 087/122] Delete RSA_hasted.py --- RSA_hasted.py | 79 --------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 RSA_hasted.py diff --git a/RSA_hasted.py b/RSA_hasted.py deleted file mode 100644 index f553868..0000000 --- a/RSA_hasted.py +++ /dev/null @@ -1,79 +0,0 @@ -from banner import * -banner() - -# N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 -# C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 -# N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 -# C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 -# N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 -# C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 - - - -def chinese_remainder(n, a): - sum = 0 - prod = functools.reduce(lambda a, b: a*b, n) - for n_i, a_i in zip(n, a): - p = prod // n_i - sum += a_i * mul_inv(p, n_i) * p - return sum % prod - -def mul_inv(a, b): - b0 = b - x0, x1 = 0, 1 - if b == 1: return 1 - while a > 1: - q = a // b - a, b = b, a%b - x0, x1 = x1 - q * x0, x0 - if x1 < 0: x1 += b0 - return x1 - -def inv_pow(c, e): - low = -1 - high = c+1 - while low + 1 < high: - m = (low + high) // 2 - p = pow(m, e) - if p < c: - low = m - else: - high = m - m = high - assert pow(m, e) == c - return m - - -try: - import functools - import itertools - - C1 = int(raw_input(">>> c1 = ")) - C2 = int(raw_input(">>> c2 = ")) - C3 = int(raw_input(">>> c3 = ")) - N1 = int(raw_input(">>> n1 = ")) - N2 = int(raw_input(">>> n2 = ")) - N3 = int(raw_input(">>> n3 = ")) - N = [N1, N2, N3] - C = [C1, C2, C3] - e = len(N) - print "e = ",e - slowprint("\n[+] Please Wait ... \033[95m\n") - - a = chinese_remainder(N, C) - for n, c in zip(N, C): - assert a % n == c - m = inv_pow(a, e) - decode = (hex(m)[2:]).replace('L','') - slowprint("[+] The PlainText = ") - print decode.decode("hex") -except ValueError: - slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except ImportError: - slowprint("\n[-] Module Not Setup") -except: - slowprint("\n[-] False Attack !") From 6ca814667e3c582a999b705783148e538e577534 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:11 +0200 Subject: [PATCH 088/122] Delete RSA_multiPrime1.py --- RSA_multiPrime1.py | 57 ---------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 RSA_multiPrime1.py diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py deleted file mode 100644 index 3daabcc..0000000 --- a/RSA_multiPrime1.py +++ /dev/null @@ -1,57 +0,0 @@ -from banner import * -banner() - -""" -c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 -n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 -e= 65537 -prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] -""" - -try: - from ecm import * - import binascii - c = int(raw_input(">>> c = ")) - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - slowprint("\n[+] Please Wait ... ") - prime = primefactors(n) - phi = 1 - for i in prime: - phi *= i-1 - def egcd(b, n): - (x0, x1, y0, y1) = (1, 0, 0, 1) - while n != 0: - (q, b, n) = (b // n, n, b % n) - (x0, x1) = (x1, x0 - q * x1) - (y0, y1) = (y1, y0 - q * y1) - return (b, x0, y0) - def modinv(a, m): - g, x, y = egcd(a, m) - if g != 1: - raise Exception('No modular inverse') - return x%m - d = modinv(e, phi) - m = pow(c, d, n) - def hex_pair(x): - return ('0' * (len(x) % 2)) + x - m_hex = '{:x}'.format(m) - m_hex = hex_pair(m_hex) - msg = binascii.unhexlify(m_hex) - slowprint("\n[+] The PlainText = ") - print(msg.decode(errors="ignore")) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,n,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except Exception: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("[-] False Attack !") From c42e35d2d7a039f90457a9e96f2333c07bb617a4 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:13 +0200 Subject: [PATCH 089/122] Delete RSA_wiener.py --- RSA_wiener.py | 89 --------------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 RSA_wiener.py diff --git a/RSA_wiener.py b/RSA_wiener.py deleted file mode 100644 index 63bc446..0000000 --- a/RSA_wiener.py +++ /dev/null @@ -1,89 +0,0 @@ -from banner import * -banner() - -#Example : -""" -n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 -c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 - -""" -try: - import random - n = int(raw_input(">>> n = ")) - e = int(raw_input(">>> e = ")) - - slowprint("\n[+] Please Wait ... \033[95m\n") - - def division_euclidienne(a, b): - return (a // b, a % b) - def fraction_continue(n, d): - developpement = [] - a = n - b = d - while b != 0: - (q,r) = division_euclidienne(a,b) - developpement.append(q) - a = b - b = r - return (developpement) - def reduites_fraction_continue(a): - l=len(a) - reduites=[] - h0 = 1 - h1 = 0 - k0 = 0 - k1 = 1 - count = 0 - while count < l: - h = a[count] * h1 + h0 - h0 = h1 - h1 = h - k = a[count] * k1 + k0 - k0 = k1 - k1 = k - reduites.append((k,h)) - count += 1 - return (reduites) - def wiener(n, e): - fc = fraction_continue(e, n) - reduites = reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - slowprint("[+] Getting d ... \033[95m\n") - return (reduites[i][1]) - else: - print("[-] Sorry it's Not Wiener Attack\n") - exit(0) - - d = wiener(n,e) - print "\nd = ",d - check = raw_input("\nYou Have Cipher [y/n] : ") - if check == "y" or check == "yes": - c = int(raw_input(">>> c = ")) - slowprint("[+] Getting PlainText ... \033[92m\n") - decode = pow(c,d,n) - output = (hex(decode)[2:].replace('L','')).decode("hex") - slowprint("[+] The PlainText = \033[92m") - print output - else : - slowprint("[+] Thanx For Using X-RSA \033[95m") - exit() - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except Exception: - slowprint("\n[-] Wrong Data") -except: - slowprint("\n[-] False Attack !") From c29423e6f5ad694f7308d9dff7033f162259f4eb Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:17 +0200 Subject: [PATCH 090/122] Delete banner.py --- banner.py | 70 ------------------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 banner.py diff --git a/banner.py b/banner.py deleted file mode 100644 index 002739b..0000000 --- a/banner.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python2 -#-*- coding: utf-8 -*- -# -# author : X-Vector -# Tested on Kali Linux / Parrot Os / Ubuntu -# Simple script for RSA Attack -import sys -import platform,os -from urllib2 import * -from platform import system -def slowprint(s): - for c in s + '\n': - sys.stdout.write(c) - sys.stdout.flush() - time.sleep(4. / 100) - -clear = "" -if "Windows" in platform.system(): - clear = "cls" -if "Linux" in platform.system(): - clear = "clear" -os.system(clear) -is_windows = sys.platform.startswith('win') - -# Console Colors -if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - try: - import win_unicode_console , colorama - win_unicode_console.enable() - colorama.init() - #Now the unicode will work ^_^ - except: - print("[!] Error: Coloring libraries not installed, no coloring will be used") - G = Y = B = R = W = G = Y = B = R = W = '' - - -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - -def banner(): - print("""%s -_____ ________________ _____ _____ -\ \ / /\ \ _____\ \ / |_ - \ | | / \ /\ \ / / \ | / \\ - \ \ / / | \_\ | | | /___/|| /\ \\ - \ | / | ___/ ____\ \ | ||| | | \\ - / | \ | \ ____ / /\ \|___|/| \/ \\ - / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ - |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ - | | | | | | | | || | || | | | | | | | - |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| - %s%s -[ Version : 0.3 ]\033[92m -[ Author : X-Vector ]\033[96m -[ Github : github.com/X-Vector ]\033[93m -[ Twitter : twitter.com/@XVector11 ]\033[95m -[ Facebook: facebook.com/X.Vector1 ]\033[95m -[ GreeteZ : Karem Ali ]\033[94m - """ % (R, W,R)) From 8205c196b301bd9a34307df526009b7feaf0a84b Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:19 +0200 Subject: [PATCH 091/122] Delete ecm.py --- ecm.py | 135 --------------------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 ecm.py diff --git a/ecm.py b/ecm.py deleted file mode 100644 index 79d6ef8..0000000 --- a/ecm.py +++ /dev/null @@ -1,135 +0,0 @@ -import random - -def primesbelow(N): - # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 - # Input N>=6, Returns a list of primes, 2 <= p < N - correction = N % 6 > 1 - N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6] - sieve = [True] * (N // 3) - sieve[0] = False - for i in range(int(N ** .5) // 3 + 1): - if sieve[i]: - k = (3 * i + 1) | 1 - sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1) - sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1) - return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]] - -smallprimeset = set(primesbelow(100000)) -_smallprimeset = 100000 -def isprime(n, precision=7): - # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time - if n < 1: - raise ValueError("Out of bounds, first argument must be > 0") - elif n <= 3: - return n >= 2 - elif n % 2 == 0: - return False - elif n < _smallprimeset: - return n in smallprimeset - - - d = n - 1 - s = 0 - while d % 2 == 0: - d //= 2 - s += 1 - - for repeat in range(precision): - a = random.randrange(2, n - 2) - x = pow(a, d, n) - - if x == 1 or x == n - 1: continue - - for r in range(s - 1): - x = pow(x, 2, n) - if x == 1: return False - if x == n - 1: break - else: return False - - return True - -# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ -def pollard_brent(n): - if n % 2 == 0: return 2 - if n % 3 == 0: return 3 - - y, c, m = random.randint(1, n-1), random.randint(1, n-1), random.randint(1, n-1) - g, r, q = 1, 1, 1 - while g == 1: - x = y - for i in range(r): - y = (pow(y, 2, n) + c) % n - - k = 0 - while k < r and g==1: - ys = y - for i in range(min(m, r-k)): - y = (pow(y, 2, n) + c) % n - q = q * abs(x-y) % n - g = gcd(q, n) - k += m - r *= 2 - if g == n: - while True: - ys = (pow(ys, 2, n) + c) % n - g = gcd(abs(x - ys), n) - if g > 1: - break - - return g - -smallprimes = primesbelow(1000) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 -def primefactors(n, sort=False): - factors = [] - - for checker in smallprimes: - while n % checker == 0: - factors.append(checker) - n //= checker - if checker > n: break - - if n < 2: return factors - - while n > 1: - if isprime(n): - factors.append(n) - break - factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent - factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent - n //= factor - - if sort: factors.sort() - - return factors - -def factorization(n): - factors = {} - for p1 in primefactors(n): - try: - factors[p1] += 1 - except KeyError: - factors[p1] = 1 - return factors - -totients = {} -def totient(n): - if n == 0: return 1 - - try: return totients[n] - except KeyError: pass - - tot = 1 - for p, exp in factorization(n).items(): - tot *= (p - 1) * p ** (exp - 1) - - totients[n] = tot - return tot - -def gcd(a, b): - if a == b: return a - while b > 0: a, b = b, a % b - return a - -def lcm(a, b): - return abs((a // gcd(a, b)) * b) - From 4b26bf0c0b1a70cea57d5d21e7cbe24c9bfeb48e Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:21 +0200 Subject: [PATCH 092/122] Delete factordb.py --- factordb.py | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 factordb.py diff --git a/factordb.py b/factordb.py deleted file mode 100644 index affef52..0000000 --- a/factordb.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function, unicode_literals -import requests - - -ENDPOINT = "http://factordb.com/api" - - -class FactorDB(): - def __init__(self, n): - self.n = n - self.result = None - - def connect(self, reconnect=False): - if self.result and not reconnect: - return self.result - self.result = requests.get(ENDPOINT, params={"query": str(self.n)}) - return self.result - - def get_id(self): - if self.result: - return self.result.json().get("id") - return None - - def get_status(self): - if self.result: - return self.result.json().get("status") - return None - - def get_factor_from_api(self): - if self.result: - return self.result.json().get("factors") - return None - - def get_factor_list(self): - """ - get_factors: [['2', 3], ['3', 2]] - Returns: [2, 2, 2, 3, 3] - """ - factors = self.get_factor_from_api() - if not factors: - return [] - ml = [[int(x)] * y for x, y in factors] - return [y for x in ml for y in x] - From 2542f39059bade8cc65b65a01c466a7aec2de495 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:37:25 +0200 Subject: [PATCH 093/122] Delete fermat.py --- fermat.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 fermat.py diff --git a/fermat.py b/fermat.py deleted file mode 100644 index 2e85afe..0000000 --- a/fermat.py +++ /dev/null @@ -1,19 +0,0 @@ -from gmpy2 import isqrt -from banner import * -def fermat(n): - a = isqrt(n) - b2 = a*a - n - b = isqrt(n) - while b*b != b2: - a = a + 1 - b2 = a*a - n - b = isqrt(b2) - if b > n : - print "\n%s[-] Sorry Can't Factorize Number%s"%(R,R) - exit() - p = a+b - q = a-b - print "%sp =%s"%(Y,G),p - print "%sq =%s"%(Y,G),q - - From 3471e37931debb277389f6777655d078a7198c06 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:38:27 +0200 Subject: [PATCH 094/122] Create s --- Factorizations/s | 1 + 1 file changed, 1 insertion(+) create mode 100644 Factorizations/s diff --git a/Factorizations/s b/Factorizations/s new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Factorizations/s @@ -0,0 +1 @@ + From 0fa8be73d74786fb05b3b6888af19390b90bf932 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:39:21 +0200 Subject: [PATCH 095/122] Add files via upload --- Factorizations/ecm.py | 135 +++++++ Factorizations/factordb.py | 45 +++ Factorizations/fermat.py | 19 + Factorizations/qs.py | 788 +++++++++++++++++++++++++++++++++++++ 4 files changed, 987 insertions(+) create mode 100644 Factorizations/ecm.py create mode 100644 Factorizations/factordb.py create mode 100644 Factorizations/fermat.py create mode 100644 Factorizations/qs.py diff --git a/Factorizations/ecm.py b/Factorizations/ecm.py new file mode 100644 index 0000000..79d6ef8 --- /dev/null +++ b/Factorizations/ecm.py @@ -0,0 +1,135 @@ +import random + +def primesbelow(N): + # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 + # Input N>=6, Returns a list of primes, 2 <= p < N + correction = N % 6 > 1 + N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6] + sieve = [True] * (N // 3) + sieve[0] = False + for i in range(int(N ** .5) // 3 + 1): + if sieve[i]: + k = (3 * i + 1) | 1 + sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1) + sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1) + return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]] + +smallprimeset = set(primesbelow(100000)) +_smallprimeset = 100000 +def isprime(n, precision=7): + # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time + if n < 1: + raise ValueError("Out of bounds, first argument must be > 0") + elif n <= 3: + return n >= 2 + elif n % 2 == 0: + return False + elif n < _smallprimeset: + return n in smallprimeset + + + d = n - 1 + s = 0 + while d % 2 == 0: + d //= 2 + s += 1 + + for repeat in range(precision): + a = random.randrange(2, n - 2) + x = pow(a, d, n) + + if x == 1 or x == n - 1: continue + + for r in range(s - 1): + x = pow(x, 2, n) + if x == 1: return False + if x == n - 1: break + else: return False + + return True + +# https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ +def pollard_brent(n): + if n % 2 == 0: return 2 + if n % 3 == 0: return 3 + + y, c, m = random.randint(1, n-1), random.randint(1, n-1), random.randint(1, n-1) + g, r, q = 1, 1, 1 + while g == 1: + x = y + for i in range(r): + y = (pow(y, 2, n) + c) % n + + k = 0 + while k < r and g==1: + ys = y + for i in range(min(m, r-k)): + y = (pow(y, 2, n) + c) % n + q = q * abs(x-y) % n + g = gcd(q, n) + k += m + r *= 2 + if g == n: + while True: + ys = (pow(ys, 2, n) + c) % n + g = gcd(abs(x - ys), n) + if g > 1: + break + + return g + +smallprimes = primesbelow(1000) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 +def primefactors(n, sort=False): + factors = [] + + for checker in smallprimes: + while n % checker == 0: + factors.append(checker) + n //= checker + if checker > n: break + + if n < 2: return factors + + while n > 1: + if isprime(n): + factors.append(n) + break + factor = pollard_brent(n) # trial division did not fully factor, switch to pollard-brent + factors.extend(primefactors(factor)) # recurse to factor the not necessarily prime factor returned by pollard-brent + n //= factor + + if sort: factors.sort() + + return factors + +def factorization(n): + factors = {} + for p1 in primefactors(n): + try: + factors[p1] += 1 + except KeyError: + factors[p1] = 1 + return factors + +totients = {} +def totient(n): + if n == 0: return 1 + + try: return totients[n] + except KeyError: pass + + tot = 1 + for p, exp in factorization(n).items(): + tot *= (p - 1) * p ** (exp - 1) + + totients[n] = tot + return tot + +def gcd(a, b): + if a == b: return a + while b > 0: a, b = b, a % b + return a + +def lcm(a, b): + return abs((a // gcd(a, b)) * b) + diff --git a/Factorizations/factordb.py b/Factorizations/factordb.py new file mode 100644 index 0000000..affef52 --- /dev/null +++ b/Factorizations/factordb.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function, unicode_literals +import requests + + +ENDPOINT = "http://factordb.com/api" + + +class FactorDB(): + def __init__(self, n): + self.n = n + self.result = None + + def connect(self, reconnect=False): + if self.result and not reconnect: + return self.result + self.result = requests.get(ENDPOINT, params={"query": str(self.n)}) + return self.result + + def get_id(self): + if self.result: + return self.result.json().get("id") + return None + + def get_status(self): + if self.result: + return self.result.json().get("status") + return None + + def get_factor_from_api(self): + if self.result: + return self.result.json().get("factors") + return None + + def get_factor_list(self): + """ + get_factors: [['2', 3], ['3', 2]] + Returns: [2, 2, 2, 3, 3] + """ + factors = self.get_factor_from_api() + if not factors: + return [] + ml = [[int(x)] * y for x, y in factors] + return [y for x in ml for y in x] + diff --git a/Factorizations/fermat.py b/Factorizations/fermat.py new file mode 100644 index 0000000..cf93ea9 --- /dev/null +++ b/Factorizations/fermat.py @@ -0,0 +1,19 @@ +from gmpy2 import isqrt +from banner import * +def fermat(n): + a = isqrt(n) + b2 = a*a - n + b = isqrt(n) + while b*b != b2: + a = a + 1 + b2 = a*a - n + b = isqrt(b2) + if b > n : + print("\n%s[-] Sorry Can't Factorize Number%s"%(R,R)) + exit() + p = a+b + q = a-b + print("%sp =%s"%(Y,G),p) + print("%sq =%s"%(Y,G),q) + + diff --git a/Factorizations/qs.py b/Factorizations/qs.py new file mode 100644 index 0000000..2127ab2 --- /dev/null +++ b/Factorizations/qs.py @@ -0,0 +1,788 @@ +from banner import * +banner() + + +from math import log,sqrt, ceil, floor +import random +from fractions import gcd +import sys +from builtins import ValueError + +MAX_DIGITS_POLLARD = 30 +POLLARD_QUICK_ITERATIONS = 20 +MIN_DIGITS_POLLARD_QUICK2 = 45 +POLLARD_QUICK2_ITERATIONS = 25 +SIQS_TRIAL_DIVISION_EPS = 25 +SIQS_MIN_PRIME_POLYNOMIAL = 400 +SIQS_MAX_PRIME_POLYNOMIAL = 4000 + +MILLER_RABIN_ITERATIONS = 50 + + +class Polynomial: + + def __init__(self, coeff=[], a=None, b=None): + self.coeff = coeff + self.a = a + self.b = b + + def eval(self, x): + res = 0 + for a in self.coeff[::-1]: + res *= x + res += a + return res + + +class FactorBasePrime: + + def __init__(self, p, tmem, lp): + self.p = p + self.soln1 = None + self.soln2 = None + self.tmem = tmem + self.lp = lp + self.ainv = None + + +def lowest_set_bit(a): + b = (a & -a) + low_bit = -1 + while (b): + b >>= 1 + low_bit += 1 + return low_bit + + +def to_bits(k): + + k_binary = bin(k)[2:] + return (bit == '1' for bit in k_binary[::-1]) + + +def pow_mod(a, k, m): + + r = 1 + b = a + for bit in to_bits(k): + if bit: + r = (r * b) % m + b = (b * b) % m + return r + + +def is_quadratic_residue(a, p): + return legendre(a, (p - 1) // 2, 1, p) == 1 + + +def legendre(a, q, l, n): + x = q ** l + if x == 0: + return 1 + + z = 1 + a %= n + + while x != 0: + if x % 2 == 0: + a = (a ** 2) % n + x //= 2 + else: + x -= 1 + z = (z * a) % n + return z + + +def sqrt_mod_prime(a, p): + # Algorithm from http://www.mersennewiki.org/index.php/Modular_Square_Root + assert a < p + assert is_probable_prime(p) + if a == 0: + return 0 + if p == 2: + return a + if p % 2 == 0: + return None + p_mod_8 = p % 8 + if p_mod_8 == 1: + # Shanks method + q = p // 8 + e = 3 + while q % 2 == 0: + q //= 2 + e += 1 + while True: + x = random.randint(2, p - 1) + z = pow_mod(x, q, p) + if pow_mod(z, 2 ** (e - 1), p) != 1: + break + y = z + r = e + x = pow_mod(a, (q - 1) // 2, p) + v = (a * x) % p + w = (v * x) % p + while True: + if w == 1: + return v + k = 1 + while pow_mod(w, 2 ** k, p) != 1: + k += 1 + d = pow_mod(y, 2 ** (r - k - 1), p) + y = (d ** 2) % p + r = k + v = (d * v) % p + w = (w * y) % p + elif p_mod_8 == 5: + v = pow_mod(2 * a, (p - 5) // 8, p) + i = (2 * a * v * v) % p + return (a * v * (i - 1)) % p + else: + return pow_mod(a, (p + 1) // 4, p) + + +def inv_mod(a, m): + return eea(a, m)[0] % m + + +def eea(a, b): + + if a == 0: + return (0, 1, b) + x = eea(b % a, a) + return (x[1] - b // a * x[0], x[0], x[2]) + + +def is_probable_prime(a): + + if a == 2: + return True + if a == 1 or a % 2 == 0: + return False + return primality_test_miller_rabin(a, MILLER_RABIN_ITERATIONS) + + +def primality_test_miller_rabin(a, iterations): + m = a - 1 + lb = lowest_set_bit(m) + m >>= lb + + for _ in range(iterations): + b = random.randint(2, a - 1) + j = 0 + z = pow_mod(b, m, a) + while not ((j == 0 and z == 1) or z == a - 1): + if (j > 0 and z == 1 or j + 1 == lb): + return False + j += 1 + z = (z * z) % a + + return True + + +def siqs_factor_base_primes(n, nf): + + global small_primes + factor_base = [] + for p in small_primes: + if is_quadratic_residue(n, p): + t = sqrt_mod_prime(n % p, p) + lp = round(log2(p)) + factor_base.append(FactorBasePrime(p, t, lp)) + if len(factor_base) >= nf: + break + return factor_base + + +def siqs_find_first_poly(n, m, factor_base): + + p_min_i = None + p_max_i = None + for i, fb in enumerate(factor_base): + if p_min_i is None and fb.p >= SIQS_MIN_PRIME_POLYNOMIAL: + p_min_i = i + if p_max_i is None and fb.p > SIQS_MAX_PRIME_POLYNOMIAL: + p_max_i = i - 1 + break + + # The following may happen if the factor base is small, make sure + # that we have enough primes. + if p_max_i is None: + p_max_i = len(factor_base) - 1 + if p_min_i is None or p_max_i - p_min_i < 20: + p_min_i = min(p_min_i, 5) + + target = sqrt(2 * float(n)) / m + target1 = target / ((factor_base[p_min_i].p + + factor_base[p_max_i].p) / 2) ** 0.5 + + # find q such that the product of factor_base[q_i] is approximately + # sqrt(2 * n) / m; try a few different sets to find a good one + best_q, best_a, best_ratio = None, None, None + for _ in range(30): + a = 1 + q = [] + + while a < target1: + p_i = 0 + while p_i == 0 or p_i in q: + p_i = random.randint(p_min_i, p_max_i) + p = factor_base[p_i].p + a *= p + q.append(p_i) + + ratio = a / target + + # ratio too small seems to be not good + if (best_ratio is None or (ratio >= 0.9 and ratio < best_ratio) or + best_ratio < 0.9 and ratio > best_ratio): + best_q = q + best_a = a + best_ratio = ratio + a = best_a + q = best_q + + s = len(q) + B = [] + for l in range(s): + fb_l = factor_base[q[l]] + q_l = fb_l.p + assert a % q_l == 0 + gamma = (fb_l.tmem * inv_mod(a // q_l, q_l)) % q_l + if gamma > q_l // 2: + gamma = q_l - gamma + B.append(a // q_l * gamma) + + b = sum(B) % a + b_orig = b + if (2 * b > a): + b = a - b + + assert 0 < b + assert 2 * b <= a + assert ((b * b - n) % a == 0) + + g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) + h = Polynomial([b, a]) + for fb in factor_base: + if a % fb.p != 0: + fb.ainv = inv_mod(a, fb.p) + fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p + fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p + + return g, h, B + + +def siqs_find_next_poly(n, factor_base, i, g, B): + + v = lowest_set_bit(i) + 1 + z = -1 if ceil(i / (2 ** v)) % 2 == 1 else 1 + b = (g.b + 2 * z * B[v - 1]) % g.a + a = g.a + b_orig = b + if (2 * b > a): + b = a - b + assert ((b * b - n) % a == 0) + + g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) + h = Polynomial([b, a]) + for fb in factor_base: + if a % fb.p != 0: + fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p + fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p + + return g, h + + +def siqs_sieve(factor_base, m): + sieve_array = [0] * (2 * m + 1) + for fb in factor_base: + if fb.soln1 is None: + continue + p = fb.p + i_start_1 = -((m + fb.soln1) // p) + a_start_1 = fb.soln1 + i_start_1 * p + lp = fb.lp + if p > 20: + for a in range(a_start_1 + m, 2 * m + 1, p): + sieve_array[a] += lp + + i_start_2 = -((m + fb.soln2) // p) + a_start_2 = fb.soln2 + i_start_2 * p + for a in range(a_start_2 + m, 2 * m + 1, p): + sieve_array[a] += lp + return sieve_array + + +def siqs_trial_divide(a, factor_base): + + divisors_idx = [] + for i, fb in enumerate(factor_base): + if a % fb.p == 0: + exp = 0 + while a % fb.p == 0: + a //= fb.p + exp += 1 + divisors_idx.append((i, exp)) + if a == 1: + return divisors_idx + return None + + +def siqs_trial_division(n, sieve_array, factor_base, smooth_relations, g, h, m, + req_relations): + + sqrt_n = sqrt(float(n)) + limit = log2(m * sqrt_n) - SIQS_TRIAL_DIVISION_EPS + for (i, sa) in enumerate(sieve_array): + if sa >= limit: + x = i - m + gx = g.eval(x) + divisors_idx = siqs_trial_divide(gx, factor_base) + if divisors_idx is not None: + u = h.eval(x) + v = gx + assert (u * u) % n == v % n + smooth_relations.append((u, v, divisors_idx)) + if (len(smooth_relations) >= req_relations): + return True + return False + + +def siqs_build_matrix(factor_base, smooth_relations): + fb = len(factor_base) + M = [] + for sr in smooth_relations: + mi = [0] * fb + for j, exp in sr[2]: + mi[j] = exp % 2 + M.append(mi) + return M + + +def siqs_build_matrix_opt(M): + + m = len(M[0]) + cols_binary = [""] * m + for mi in M: + for j, mij in enumerate(mi): + cols_binary[j] += "1" if mij else "0" + return [int(cols_bin[::-1], 2) for cols_bin in cols_binary], len(M), m + + +def add_column_opt(M_opt, tgt, src): + + M_opt[tgt] ^= M_opt[src] + + +def find_pivot_column_opt(M_opt, j): + + if M_opt[j] == 0: + return None + return lowest_set_bit(M_opt[j]) + + +def siqs_solve_matrix_opt(M_opt, n, m): + + row_is_marked = [False] * n + pivots = [-1] * m + for j in range(m): + i = find_pivot_column_opt(M_opt, j) + if i is not None: + pivots[j] = i + row_is_marked[i] = True + for k in range(m): + if k != j and (M_opt[k] >> i) & 1: # test M[i][k] == 1 + add_column_opt(M_opt, k, j) + perf_squares = [] + for i in range(n): + if not row_is_marked[i]: + perfect_sq_indices = [i] + for j in range(m): + if (M_opt[j] >> i) & 1: # test M[i][j] == 1 + perfect_sq_indices.append(pivots[j]) + perf_squares.append(perfect_sq_indices) + return perf_squares + + +def siqs_calc_sqrts(square_indices, smooth_relations): + + res = [1, 1] + for idx in square_indices: + res[0] *= smooth_relations[idx][0] + res[1] *= smooth_relations[idx][1] + res[1] = sqrt_int(res[1]) + return res + + +def sqrt_int(n): + + a = n + s = 0 + o = 1 << (int(log(n,2)) & ~1) + while o != 0: + t = s + o + if a >= t: + a -= t + s = (s >> 1) + o + else: + s >>= 1 + o >>= 2 + assert s * s == n + return s + + +def kth_root_int(n, k): + + u = n + s = n + 1 + while u < s: + s = u + t = (k - 1) * s + n // pow(s, k - 1) + u = t // k + return s + + +def siqs_factor_from_square(n, square_indices, smooth_relations): + sqrt1, sqrt2 = siqs_calc_sqrts(square_indices, smooth_relations) + assert (sqrt1 * sqrt1) % n == (sqrt2 * sqrt2) % n + return gcd(abs(sqrt1 - sqrt2), n) + + +def siqs_find_factors(n, perfect_squares, smooth_relations): + + factors = [] + rem = n + non_prime_factors = set() + prime_factors = set() + for square_indices in perfect_squares: + fact = siqs_factor_from_square(n, square_indices, smooth_relations) + if fact != 1 and fact != rem: + if is_probable_prime(fact): + if fact not in prime_factors: + prime_factors.add(fact) + + while rem % fact == 0: + factors.append(fact) + rem //= fact + + if rem == 1: + break + if is_probable_prime(rem): + factors.append(rem) + rem = 1 + break + else: + if fact not in non_prime_factors: + non_prime_factors.add(fact) + + if rem != 1 and non_prime_factors: + non_prime_factors.add(rem) + for fact in sorted(siqs_find_more_factors_gcd(non_prime_factors)): + while fact != 1 and rem % fact == 0: + factors.append(fact) + rem //= fact + if rem == 1 or is_probable_prime(rem): + break + + if rem != 1: + factors.append(rem) + return factors + + +def siqs_find_more_factors_gcd(numbers): + res = set() + for n in numbers: + res.add(n) + for m in numbers: + if n != m: + fact = gcd(n, m) + if fact != 1 and fact != n and fact != m: + if fact not in res: + res.add(fact) + res.add(n // fact) + res.add(m // fact) + return res + + +def siqs_choose_nf_m(d): + # Using similar parameters as msieve-1.52 + if d <= 34: + return 200, 65536 + if d <= 36: + return 300, 65536 + if d <= 38: + return 400, 65536 + if d <= 40: + return 500, 65536 + if d <= 42: + return 600, 65536 + if d <= 44: + return 700, 65536 + if d <= 48: + return 1000, 65536 + if d <= 52: + return 1200, 65536 + if d <= 56: + return 2000, 65536 * 3 + if d <= 60: + return 4000, 65536 * 3 + if d <= 66: + return 6000, 65536 * 3 + if d <= 74: + return 10000, 65536 * 3 + if d <= 80: + return 30000, 65536 * 3 + if d <= 88: + return 50000, 65536 * 3 + if d <= 94: + return 60000, 65536 * 9 + return 100000, 65536 * 9 + + +def siqs_factorise(n): + + dig = len(str(n)) + nf, m = siqs_choose_nf_m(dig) + + factor_base = siqs_factor_base_primes(n, nf) + + required_relations_ratio = 1.05 + success = False + smooth_relations = [] + prev_cnt = 0 + i_poly = 0 + while not success: + required_relations = round(len(factor_base) * required_relations_ratio) + enough_relations = False + while not enough_relations: + if i_poly == 0: + g, h, B = siqs_find_first_poly(n, m, factor_base) + else: + g, h = siqs_find_next_poly(n, factor_base, i_poly, g, B) + i_poly += 1 + if i_poly >= 2 ** (len(B) - 1): + i_poly = 0 + sieve_array = siqs_sieve(factor_base, m) + enough_relations = siqs_trial_division( + n, sieve_array, factor_base, smooth_relations, + g, h, m, required_relations) + + if (len(smooth_relations) >= required_relations or + i_poly % 8 == 0 and len(smooth_relations) > prev_cnt): + + prev_cnt = len(smooth_relations) + + + M = siqs_build_matrix(factor_base, smooth_relations) + M_opt, M_n, M_m = siqs_build_matrix_opt(M) + + + perfect_squares = siqs_solve_matrix_opt(M_opt, M_n, M_m) + + + factors = siqs_find_factors(n, perfect_squares, smooth_relations) + if len(factors) > 1: + success = True + else: + required_relations_ratio += 0.05 + + return factors + + +def check_factor(n, i, factors): + while n % i == 0: + n //= i + factors.append(i) + if is_probable_prime(n): + factors.append(n) + n = 1 + return n + + +def trial_div_init_primes(n, upper_bound): + global small_primes + is_prime = [True] * (upper_bound + 1) + is_prime[0:2] = [False] * 2 + factors = [] + small_primes = [] + max_i = sqrt_int(upper_bound) + rem = n + for i in range(2, max_i + 1): + if is_prime[i]: + small_primes.append(i) + rem = check_factor(rem, i, factors) + if rem == 1: + return factors, 1 + + for j in (range(i ** 2, upper_bound + 1, i)): + is_prime[j] = False + + for i in range(max_i + 1, upper_bound + 1): + if is_prime[i]: + small_primes.append(i) + rem = check_factor(rem, i, factors) + if rem == 1: + return factors, 1 + return factors, rem + + +def pollard_brent_f(c, n, x): + x1 = (x * x) % n + c + if x1 >= n: + x1 -= n + assert x1 >= 0 and x1 < n + return x1 + + +def pollard_brent_find_factor(n, max_iter=None): + + y, c, m = (random.randint(1, n - 1) for _ in range(3)) + r, q, g = 1, 1, 1 + i = 0 + while g == 1: + x = y + for _ in range(r): + y = pollard_brent_f(c, n, y) + k = 0 + while k < r and g == 1: + ys = y + for _ in range(min(m, r - k)): + y = pollard_brent_f(c, n, y) + q = (q * abs(x - y)) % n + g = gcd(q, n) + k += m + r *= 2 + if max_iter: + i += 1 + if (i == max_iter): + return None + + if g == n: + while True: + ys = pollard_brent_f(c, n, ys) + g = gcd(abs(x - ys), n) + if g > 1: + break + return g + + +def pollard_brent_quick(n, factors): + + rem = n + while True: + if is_probable_prime(rem): + factors.append(rem) + rem = 1 + break + + digits = len(str(n)) + if digits < MIN_DIGITS_POLLARD_QUICK2: + max_iter = POLLARD_QUICK_ITERATIONS + else: + max_iter = POLLARD_QUICK2_ITERATIONS + + f = pollard_brent_find_factor(rem, max_iter) + if f and f < rem: + if is_probable_prime(f): + factors.append(f) + assert rem % f == 0 + rem //= f + else: + rem_f = pollard_brent_quick(f, factors) + rem = (rem // f) * rem_f + else: + break + return rem + + +def check_perfect_power(n): + largest_checked_prime = small_primes[-1] + for b in small_primes: + bth_root = kth_root_int(n, b) + if bth_root < largest_checked_prime: + break + if (bth_root ** b == n): + return (bth_root, b) + return None + + +def find_prime_factors(n): + perfect_power = check_perfect_power(n) + if perfect_power: + factors = [perfect_power[0]] + else: + digits = len(str(n)) + if digits <= MAX_DIGITS_POLLARD: + factors = [pollard_brent_find_factor(n)] + else: + factors = siqs_factorise(n) + + prime_factors = [] + for f in set(factors): + for pf in find_all_prime_factors(f): + prime_factors.append(pf) + + return prime_factors + + +def find_all_prime_factors(n): + rem = n + factors = [] + + while rem > 1: + if is_probable_prime(rem): + factors.append(rem) + break + + for f in find_prime_factors(rem): + assert is_probable_prime(f) + assert rem % f == 0 + while rem % f == 0: + rem //= f + factors.append(f) + + return factors + + +def product(factors): + prod = 1 + for f in factors: + prod *= f + return prod + + +def factorise(n): + + if type(n) is long: + return "Long" + if type(n) != int or n < 1: + return False + + if n == 1: + return [] + + if is_probable_prime(n): + return [n] + + factors, rem = trial_div_init_primes(n, 1000000) + + if factors: + pass + else: + if rem != 1: + digits = len(str(rem)) + if digits > MAX_DIGITS_POLLARD: + rem = pollard_brent_quick(rem, factors) + if rem > 1: + for fr in find_all_prime_factors(rem): + factors.append(fr) + + factors.sort() + assert product(factors) == n + for p in factors: + assert is_probable_prime(p) + return factors + + + + From 193e6ef8b89de1484a9a2747523c6b0af9befa84 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:39:34 +0200 Subject: [PATCH 096/122] Delete qs.py --- qs.py | 788 ---------------------------------------------------------- 1 file changed, 788 deletions(-) delete mode 100644 qs.py diff --git a/qs.py b/qs.py deleted file mode 100644 index 2127ab2..0000000 --- a/qs.py +++ /dev/null @@ -1,788 +0,0 @@ -from banner import * -banner() - - -from math import log,sqrt, ceil, floor -import random -from fractions import gcd -import sys -from builtins import ValueError - -MAX_DIGITS_POLLARD = 30 -POLLARD_QUICK_ITERATIONS = 20 -MIN_DIGITS_POLLARD_QUICK2 = 45 -POLLARD_QUICK2_ITERATIONS = 25 -SIQS_TRIAL_DIVISION_EPS = 25 -SIQS_MIN_PRIME_POLYNOMIAL = 400 -SIQS_MAX_PRIME_POLYNOMIAL = 4000 - -MILLER_RABIN_ITERATIONS = 50 - - -class Polynomial: - - def __init__(self, coeff=[], a=None, b=None): - self.coeff = coeff - self.a = a - self.b = b - - def eval(self, x): - res = 0 - for a in self.coeff[::-1]: - res *= x - res += a - return res - - -class FactorBasePrime: - - def __init__(self, p, tmem, lp): - self.p = p - self.soln1 = None - self.soln2 = None - self.tmem = tmem - self.lp = lp - self.ainv = None - - -def lowest_set_bit(a): - b = (a & -a) - low_bit = -1 - while (b): - b >>= 1 - low_bit += 1 - return low_bit - - -def to_bits(k): - - k_binary = bin(k)[2:] - return (bit == '1' for bit in k_binary[::-1]) - - -def pow_mod(a, k, m): - - r = 1 - b = a - for bit in to_bits(k): - if bit: - r = (r * b) % m - b = (b * b) % m - return r - - -def is_quadratic_residue(a, p): - return legendre(a, (p - 1) // 2, 1, p) == 1 - - -def legendre(a, q, l, n): - x = q ** l - if x == 0: - return 1 - - z = 1 - a %= n - - while x != 0: - if x % 2 == 0: - a = (a ** 2) % n - x //= 2 - else: - x -= 1 - z = (z * a) % n - return z - - -def sqrt_mod_prime(a, p): - # Algorithm from http://www.mersennewiki.org/index.php/Modular_Square_Root - assert a < p - assert is_probable_prime(p) - if a == 0: - return 0 - if p == 2: - return a - if p % 2 == 0: - return None - p_mod_8 = p % 8 - if p_mod_8 == 1: - # Shanks method - q = p // 8 - e = 3 - while q % 2 == 0: - q //= 2 - e += 1 - while True: - x = random.randint(2, p - 1) - z = pow_mod(x, q, p) - if pow_mod(z, 2 ** (e - 1), p) != 1: - break - y = z - r = e - x = pow_mod(a, (q - 1) // 2, p) - v = (a * x) % p - w = (v * x) % p - while True: - if w == 1: - return v - k = 1 - while pow_mod(w, 2 ** k, p) != 1: - k += 1 - d = pow_mod(y, 2 ** (r - k - 1), p) - y = (d ** 2) % p - r = k - v = (d * v) % p - w = (w * y) % p - elif p_mod_8 == 5: - v = pow_mod(2 * a, (p - 5) // 8, p) - i = (2 * a * v * v) % p - return (a * v * (i - 1)) % p - else: - return pow_mod(a, (p + 1) // 4, p) - - -def inv_mod(a, m): - return eea(a, m)[0] % m - - -def eea(a, b): - - if a == 0: - return (0, 1, b) - x = eea(b % a, a) - return (x[1] - b // a * x[0], x[0], x[2]) - - -def is_probable_prime(a): - - if a == 2: - return True - if a == 1 or a % 2 == 0: - return False - return primality_test_miller_rabin(a, MILLER_RABIN_ITERATIONS) - - -def primality_test_miller_rabin(a, iterations): - m = a - 1 - lb = lowest_set_bit(m) - m >>= lb - - for _ in range(iterations): - b = random.randint(2, a - 1) - j = 0 - z = pow_mod(b, m, a) - while not ((j == 0 and z == 1) or z == a - 1): - if (j > 0 and z == 1 or j + 1 == lb): - return False - j += 1 - z = (z * z) % a - - return True - - -def siqs_factor_base_primes(n, nf): - - global small_primes - factor_base = [] - for p in small_primes: - if is_quadratic_residue(n, p): - t = sqrt_mod_prime(n % p, p) - lp = round(log2(p)) - factor_base.append(FactorBasePrime(p, t, lp)) - if len(factor_base) >= nf: - break - return factor_base - - -def siqs_find_first_poly(n, m, factor_base): - - p_min_i = None - p_max_i = None - for i, fb in enumerate(factor_base): - if p_min_i is None and fb.p >= SIQS_MIN_PRIME_POLYNOMIAL: - p_min_i = i - if p_max_i is None and fb.p > SIQS_MAX_PRIME_POLYNOMIAL: - p_max_i = i - 1 - break - - # The following may happen if the factor base is small, make sure - # that we have enough primes. - if p_max_i is None: - p_max_i = len(factor_base) - 1 - if p_min_i is None or p_max_i - p_min_i < 20: - p_min_i = min(p_min_i, 5) - - target = sqrt(2 * float(n)) / m - target1 = target / ((factor_base[p_min_i].p + - factor_base[p_max_i].p) / 2) ** 0.5 - - # find q such that the product of factor_base[q_i] is approximately - # sqrt(2 * n) / m; try a few different sets to find a good one - best_q, best_a, best_ratio = None, None, None - for _ in range(30): - a = 1 - q = [] - - while a < target1: - p_i = 0 - while p_i == 0 or p_i in q: - p_i = random.randint(p_min_i, p_max_i) - p = factor_base[p_i].p - a *= p - q.append(p_i) - - ratio = a / target - - # ratio too small seems to be not good - if (best_ratio is None or (ratio >= 0.9 and ratio < best_ratio) or - best_ratio < 0.9 and ratio > best_ratio): - best_q = q - best_a = a - best_ratio = ratio - a = best_a - q = best_q - - s = len(q) - B = [] - for l in range(s): - fb_l = factor_base[q[l]] - q_l = fb_l.p - assert a % q_l == 0 - gamma = (fb_l.tmem * inv_mod(a // q_l, q_l)) % q_l - if gamma > q_l // 2: - gamma = q_l - gamma - B.append(a // q_l * gamma) - - b = sum(B) % a - b_orig = b - if (2 * b > a): - b = a - b - - assert 0 < b - assert 2 * b <= a - assert ((b * b - n) % a == 0) - - g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) - h = Polynomial([b, a]) - for fb in factor_base: - if a % fb.p != 0: - fb.ainv = inv_mod(a, fb.p) - fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p - fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p - - return g, h, B - - -def siqs_find_next_poly(n, factor_base, i, g, B): - - v = lowest_set_bit(i) + 1 - z = -1 if ceil(i / (2 ** v)) % 2 == 1 else 1 - b = (g.b + 2 * z * B[v - 1]) % g.a - a = g.a - b_orig = b - if (2 * b > a): - b = a - b - assert ((b * b - n) % a == 0) - - g = Polynomial([b * b - n, 2 * a * b, a * a], a, b_orig) - h = Polynomial([b, a]) - for fb in factor_base: - if a % fb.p != 0: - fb.soln1 = (fb.ainv * (fb.tmem - b)) % fb.p - fb.soln2 = (fb.ainv * (-fb.tmem - b)) % fb.p - - return g, h - - -def siqs_sieve(factor_base, m): - sieve_array = [0] * (2 * m + 1) - for fb in factor_base: - if fb.soln1 is None: - continue - p = fb.p - i_start_1 = -((m + fb.soln1) // p) - a_start_1 = fb.soln1 + i_start_1 * p - lp = fb.lp - if p > 20: - for a in range(a_start_1 + m, 2 * m + 1, p): - sieve_array[a] += lp - - i_start_2 = -((m + fb.soln2) // p) - a_start_2 = fb.soln2 + i_start_2 * p - for a in range(a_start_2 + m, 2 * m + 1, p): - sieve_array[a] += lp - return sieve_array - - -def siqs_trial_divide(a, factor_base): - - divisors_idx = [] - for i, fb in enumerate(factor_base): - if a % fb.p == 0: - exp = 0 - while a % fb.p == 0: - a //= fb.p - exp += 1 - divisors_idx.append((i, exp)) - if a == 1: - return divisors_idx - return None - - -def siqs_trial_division(n, sieve_array, factor_base, smooth_relations, g, h, m, - req_relations): - - sqrt_n = sqrt(float(n)) - limit = log2(m * sqrt_n) - SIQS_TRIAL_DIVISION_EPS - for (i, sa) in enumerate(sieve_array): - if sa >= limit: - x = i - m - gx = g.eval(x) - divisors_idx = siqs_trial_divide(gx, factor_base) - if divisors_idx is not None: - u = h.eval(x) - v = gx - assert (u * u) % n == v % n - smooth_relations.append((u, v, divisors_idx)) - if (len(smooth_relations) >= req_relations): - return True - return False - - -def siqs_build_matrix(factor_base, smooth_relations): - fb = len(factor_base) - M = [] - for sr in smooth_relations: - mi = [0] * fb - for j, exp in sr[2]: - mi[j] = exp % 2 - M.append(mi) - return M - - -def siqs_build_matrix_opt(M): - - m = len(M[0]) - cols_binary = [""] * m - for mi in M: - for j, mij in enumerate(mi): - cols_binary[j] += "1" if mij else "0" - return [int(cols_bin[::-1], 2) for cols_bin in cols_binary], len(M), m - - -def add_column_opt(M_opt, tgt, src): - - M_opt[tgt] ^= M_opt[src] - - -def find_pivot_column_opt(M_opt, j): - - if M_opt[j] == 0: - return None - return lowest_set_bit(M_opt[j]) - - -def siqs_solve_matrix_opt(M_opt, n, m): - - row_is_marked = [False] * n - pivots = [-1] * m - for j in range(m): - i = find_pivot_column_opt(M_opt, j) - if i is not None: - pivots[j] = i - row_is_marked[i] = True - for k in range(m): - if k != j and (M_opt[k] >> i) & 1: # test M[i][k] == 1 - add_column_opt(M_opt, k, j) - perf_squares = [] - for i in range(n): - if not row_is_marked[i]: - perfect_sq_indices = [i] - for j in range(m): - if (M_opt[j] >> i) & 1: # test M[i][j] == 1 - perfect_sq_indices.append(pivots[j]) - perf_squares.append(perfect_sq_indices) - return perf_squares - - -def siqs_calc_sqrts(square_indices, smooth_relations): - - res = [1, 1] - for idx in square_indices: - res[0] *= smooth_relations[idx][0] - res[1] *= smooth_relations[idx][1] - res[1] = sqrt_int(res[1]) - return res - - -def sqrt_int(n): - - a = n - s = 0 - o = 1 << (int(log(n,2)) & ~1) - while o != 0: - t = s + o - if a >= t: - a -= t - s = (s >> 1) + o - else: - s >>= 1 - o >>= 2 - assert s * s == n - return s - - -def kth_root_int(n, k): - - u = n - s = n + 1 - while u < s: - s = u - t = (k - 1) * s + n // pow(s, k - 1) - u = t // k - return s - - -def siqs_factor_from_square(n, square_indices, smooth_relations): - sqrt1, sqrt2 = siqs_calc_sqrts(square_indices, smooth_relations) - assert (sqrt1 * sqrt1) % n == (sqrt2 * sqrt2) % n - return gcd(abs(sqrt1 - sqrt2), n) - - -def siqs_find_factors(n, perfect_squares, smooth_relations): - - factors = [] - rem = n - non_prime_factors = set() - prime_factors = set() - for square_indices in perfect_squares: - fact = siqs_factor_from_square(n, square_indices, smooth_relations) - if fact != 1 and fact != rem: - if is_probable_prime(fact): - if fact not in prime_factors: - prime_factors.add(fact) - - while rem % fact == 0: - factors.append(fact) - rem //= fact - - if rem == 1: - break - if is_probable_prime(rem): - factors.append(rem) - rem = 1 - break - else: - if fact not in non_prime_factors: - non_prime_factors.add(fact) - - if rem != 1 and non_prime_factors: - non_prime_factors.add(rem) - for fact in sorted(siqs_find_more_factors_gcd(non_prime_factors)): - while fact != 1 and rem % fact == 0: - factors.append(fact) - rem //= fact - if rem == 1 or is_probable_prime(rem): - break - - if rem != 1: - factors.append(rem) - return factors - - -def siqs_find_more_factors_gcd(numbers): - res = set() - for n in numbers: - res.add(n) - for m in numbers: - if n != m: - fact = gcd(n, m) - if fact != 1 and fact != n and fact != m: - if fact not in res: - res.add(fact) - res.add(n // fact) - res.add(m // fact) - return res - - -def siqs_choose_nf_m(d): - # Using similar parameters as msieve-1.52 - if d <= 34: - return 200, 65536 - if d <= 36: - return 300, 65536 - if d <= 38: - return 400, 65536 - if d <= 40: - return 500, 65536 - if d <= 42: - return 600, 65536 - if d <= 44: - return 700, 65536 - if d <= 48: - return 1000, 65536 - if d <= 52: - return 1200, 65536 - if d <= 56: - return 2000, 65536 * 3 - if d <= 60: - return 4000, 65536 * 3 - if d <= 66: - return 6000, 65536 * 3 - if d <= 74: - return 10000, 65536 * 3 - if d <= 80: - return 30000, 65536 * 3 - if d <= 88: - return 50000, 65536 * 3 - if d <= 94: - return 60000, 65536 * 9 - return 100000, 65536 * 9 - - -def siqs_factorise(n): - - dig = len(str(n)) - nf, m = siqs_choose_nf_m(dig) - - factor_base = siqs_factor_base_primes(n, nf) - - required_relations_ratio = 1.05 - success = False - smooth_relations = [] - prev_cnt = 0 - i_poly = 0 - while not success: - required_relations = round(len(factor_base) * required_relations_ratio) - enough_relations = False - while not enough_relations: - if i_poly == 0: - g, h, B = siqs_find_first_poly(n, m, factor_base) - else: - g, h = siqs_find_next_poly(n, factor_base, i_poly, g, B) - i_poly += 1 - if i_poly >= 2 ** (len(B) - 1): - i_poly = 0 - sieve_array = siqs_sieve(factor_base, m) - enough_relations = siqs_trial_division( - n, sieve_array, factor_base, smooth_relations, - g, h, m, required_relations) - - if (len(smooth_relations) >= required_relations or - i_poly % 8 == 0 and len(smooth_relations) > prev_cnt): - - prev_cnt = len(smooth_relations) - - - M = siqs_build_matrix(factor_base, smooth_relations) - M_opt, M_n, M_m = siqs_build_matrix_opt(M) - - - perfect_squares = siqs_solve_matrix_opt(M_opt, M_n, M_m) - - - factors = siqs_find_factors(n, perfect_squares, smooth_relations) - if len(factors) > 1: - success = True - else: - required_relations_ratio += 0.05 - - return factors - - -def check_factor(n, i, factors): - while n % i == 0: - n //= i - factors.append(i) - if is_probable_prime(n): - factors.append(n) - n = 1 - return n - - -def trial_div_init_primes(n, upper_bound): - global small_primes - is_prime = [True] * (upper_bound + 1) - is_prime[0:2] = [False] * 2 - factors = [] - small_primes = [] - max_i = sqrt_int(upper_bound) - rem = n - for i in range(2, max_i + 1): - if is_prime[i]: - small_primes.append(i) - rem = check_factor(rem, i, factors) - if rem == 1: - return factors, 1 - - for j in (range(i ** 2, upper_bound + 1, i)): - is_prime[j] = False - - for i in range(max_i + 1, upper_bound + 1): - if is_prime[i]: - small_primes.append(i) - rem = check_factor(rem, i, factors) - if rem == 1: - return factors, 1 - return factors, rem - - -def pollard_brent_f(c, n, x): - x1 = (x * x) % n + c - if x1 >= n: - x1 -= n - assert x1 >= 0 and x1 < n - return x1 - - -def pollard_brent_find_factor(n, max_iter=None): - - y, c, m = (random.randint(1, n - 1) for _ in range(3)) - r, q, g = 1, 1, 1 - i = 0 - while g == 1: - x = y - for _ in range(r): - y = pollard_brent_f(c, n, y) - k = 0 - while k < r and g == 1: - ys = y - for _ in range(min(m, r - k)): - y = pollard_brent_f(c, n, y) - q = (q * abs(x - y)) % n - g = gcd(q, n) - k += m - r *= 2 - if max_iter: - i += 1 - if (i == max_iter): - return None - - if g == n: - while True: - ys = pollard_brent_f(c, n, ys) - g = gcd(abs(x - ys), n) - if g > 1: - break - return g - - -def pollard_brent_quick(n, factors): - - rem = n - while True: - if is_probable_prime(rem): - factors.append(rem) - rem = 1 - break - - digits = len(str(n)) - if digits < MIN_DIGITS_POLLARD_QUICK2: - max_iter = POLLARD_QUICK_ITERATIONS - else: - max_iter = POLLARD_QUICK2_ITERATIONS - - f = pollard_brent_find_factor(rem, max_iter) - if f and f < rem: - if is_probable_prime(f): - factors.append(f) - assert rem % f == 0 - rem //= f - else: - rem_f = pollard_brent_quick(f, factors) - rem = (rem // f) * rem_f - else: - break - return rem - - -def check_perfect_power(n): - largest_checked_prime = small_primes[-1] - for b in small_primes: - bth_root = kth_root_int(n, b) - if bth_root < largest_checked_prime: - break - if (bth_root ** b == n): - return (bth_root, b) - return None - - -def find_prime_factors(n): - perfect_power = check_perfect_power(n) - if perfect_power: - factors = [perfect_power[0]] - else: - digits = len(str(n)) - if digits <= MAX_DIGITS_POLLARD: - factors = [pollard_brent_find_factor(n)] - else: - factors = siqs_factorise(n) - - prime_factors = [] - for f in set(factors): - for pf in find_all_prime_factors(f): - prime_factors.append(pf) - - return prime_factors - - -def find_all_prime_factors(n): - rem = n - factors = [] - - while rem > 1: - if is_probable_prime(rem): - factors.append(rem) - break - - for f in find_prime_factors(rem): - assert is_probable_prime(f) - assert rem % f == 0 - while rem % f == 0: - rem //= f - factors.append(f) - - return factors - - -def product(factors): - prod = 1 - for f in factors: - prod *= f - return prod - - -def factorise(n): - - if type(n) is long: - return "Long" - if type(n) != int or n < 1: - return False - - if n == 1: - return [] - - if is_probable_prime(n): - return [n] - - factors, rem = trial_div_init_primes(n, 1000000) - - if factors: - pass - else: - if rem != 1: - digits = len(str(rem)) - if digits > MAX_DIGITS_POLLARD: - rem = pollard_brent_quick(rem, factors) - if rem > 1: - for fr in find_all_prime_factors(rem): - factors.append(fr) - - factors.sort() - assert product(factors) == n - for p in factors: - assert is_probable_prime(p) - return factors - - - - From fe1a91b10ce8824d18aa2dc2740d041caf7f6cde Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:41:06 +0200 Subject: [PATCH 097/122] Create a --- Attacks/a | 1 + 1 file changed, 1 insertion(+) create mode 100644 Attacks/a diff --git a/Attacks/a b/Attacks/a new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Attacks/a @@ -0,0 +1 @@ + From 8be7569a94011a9020472bf80ceb4cae3b806634 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:42:01 +0200 Subject: [PATCH 098/122] Delete s --- Factorizations/s | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Factorizations/s diff --git a/Factorizations/s b/Factorizations/s deleted file mode 100644 index 8b13789..0000000 --- a/Factorizations/s +++ /dev/null @@ -1 +0,0 @@ - From 089ae064f65431932977b6b3b497791144b1900b Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:43:08 +0200 Subject: [PATCH 099/122] Add files via upload --- Attack.py | 76 ++++++++++++++++++++++++++++++++++++++ Factorization.py | 53 +++++++++++++++++++++++++++ banner.py | 67 ++++++++++++++++++++++++++++++++++ utilis.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 291 insertions(+) create mode 100644 Attack.py create mode 100644 Factorization.py create mode 100644 banner.py create mode 100644 utilis.py diff --git a/Attack.py b/Attack.py new file mode 100644 index 0000000..73fa8fb --- /dev/null +++ b/Attack.py @@ -0,0 +1,76 @@ +from banner import * +banner() +print(""" +[1] - Attacks +[2] - Factorization Number +""") +check = int(input(">>> ")) +if check == 2: + import Factorization + +elif check == 1: + banner() + print(""" +[1] - Attack(c,n,e) \033[92m +[2] - Attack(c,p,q,e) \033[96m +[3] - Attack (c,n,e,{p or q}) +[4] - Attack (c,n,e,dp) +[5] - Attack(c,n,d,e,phi) \033[93m +[6] - Attack(c1,c2,c3,n1,n2,n3,e=3) \033[95m [ Hasted ] +[7] - Attack(c1,c2,e1,e2,n) \033[96m [ Common Modulus ] +[8] - Attack(c,p,q,dp,dq) \033[93m [ Chinese Remainder Theorem ] +[9] - Attack(n,e) \033[95m [ Wiener ] +[10] - Attack(c,n,d)\033[0m +[11] - Attack(c,d,n,e)\033[92m +[12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] +[13] - Attack(c,e = 3)\033[0m +[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Factor ] +[0] - Exit \033[92m + """) + x = int(input(">>> ")) + if x == 1: + os.system(clear) + import Attacks.RSA + elif x == 2: + os.system(clear) + import Attacks.RSA2 + elif x == 3: + os.system(clear) + import Attacks.RSA6 + elif x == 4: + os.system(clear) + import Attacks.RSA7 + elif x == 5: + os.system(clear) + import Attacks.RSA3 + elif x == 6: + os.system(clear) + import Attacks.RSA_hasted + elif x == 7: + os.system(clear) + import Attacks.RSA_common_modulus + elif x == 8: + os.system(clear) + import Attacks.RSA_chinese_remainder_theorem + elif x == 9: + os.system(clear) + import Attacks.RSA_wiener + elif x == 10: + os.system(clear) + import Attacks.RSA4 + elif x == 11: + os.system(clear) + import Attacks.RSA5 + elif x == 12: + os.system(clear) + import Attacks.RSA_multiPrime1 + elif x == 13: + os.system(clear) + import Attacks.RSA8 + elif x == 14: + os.system(clear) + import Attacks.RSA_common_exponent + else: + exit() +else: + exit() diff --git a/Factorization.py b/Factorization.py new file mode 100644 index 0000000..e9b2f96 --- /dev/null +++ b/Factorization.py @@ -0,0 +1,53 @@ +from banner import * +banner() + +from Factorizations.factordb import * +from Factorizations.fermat import * +from Factorizations.ecm import * +from Factorizations.qs import * + +print(""" +[1] - Factordb Factorization \033[92m +[2] - Fermat Factorization \033[96m +[3] - ECM Factorization \033[93m +[4] - Quadratic sieve Factorization \033[95m +[0] - Exit \033[92m + """) + +x = int(input(">>> ")) +#Factordb +if x == 1: + + n = int(input("%s\n>>> n = %s"%(B,B))) + print("\n[+] Please Wait ...\n") + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + print("%sprimes =%s"%(Y,Y),"%s"%(G),factordb(n)) + +#Fermet +elif x == 2: + n = int(input("%s\n>>> n = %s"%(B,B))) + print("\n[+] Please Wait ...\n") + fermat(n) + +#ECM +elif x == 3: + n = int(input("%s\n>>> n = %s"%(B,B))) + print("\n[+] Please Wait ...\n") + print("%sprimes =%s"%(Y,Y),"%s"%(G),primefactors(n)) + +elif x == 4: + N = int(input("%s\n>>> n = %s"%(B,B))) + if not factorise(N): + print("Number Must Be Greater Than 0 and Must Be Integer") + elif factorise(N) == "Long": + print("N is Too Long ") + else: + print("\n[+] Please Wait ...\n") + print ("%sprimes =%s"%(Y,Y),"%s"%(G),factorise(N)) + +else: + exit() diff --git a/banner.py b/banner.py new file mode 100644 index 0000000..f9cb3a8 --- /dev/null +++ b/banner.py @@ -0,0 +1,67 @@ +# author : X-Vector +# Tested on Kali Linux / Parrot Os / Ubuntu +# Simple script for RSA Attack +import sys +import platform,os +from platform import system +import time +def slowprint(s): + for c in s + '\n': + sys.stdout.write(c) + sys.stdout.flush() + time.sleep(4. / 100) + +clear = "" +if "Windows" in platform.system(): + clear = "cls" +if "Linux" in platform.system(): + clear = "clear" +os.system(clear) +is_windows = sys.platform.startswith('win') + +# Console Colors +if is_windows: + # Windows deserves coloring too :D + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + try: + import win_unicode_console , colorama + win_unicode_console.enable() + colorama.init() + #Now the unicode will work ^_^ + except: + print("[!] Error: Coloring libraries not installed, no coloring will be used") + G = Y = B = R = W = G = Y = B = R = W = '' + + +else: + G = '\033[92m' # green + Y = '\033[93m' # yellow + B = '\033[94m' # blue + R = '\033[91m' # red + W = '\033[0m' # white + + +def banner(): + print("""%s +_____ ________________ _____ _____ +\ \ / /\ \ _____\ \ / |_ + \ | | / \ /\ \ / / \ | / \\ + \ \ / / | \_\ | | | /___/|| /\ \\ + \ | / | ___/ ____\ \ | ||| | | \\ + / | \ | \ ____ / /\ \|___|/| \/ \\ + / /|\ \ / /\ \/ \| |/ \ \ |\ /\ \\ + |____|/ \|____| /_____/ |\______||\____\ /____/| | \_____\ \_____\\ + | | | | | | | | || | || | | | | | | | + |____| |____| |_____|/ \|_____| \|___||____|/ \|_____|\|_____| + %s%s +[ Version : 0.4 ]\033[92m +[ Author : X-Vector ]\033[96m +[ Github : github.com/X-Vector ]\033[93m +[ Twitter : twitter.com/@XVector11 ]\033[95m +[ Facebook: facebook.com/X.Vector1 ]\033[95m +[ GreeteZ : Karem Ali ]\033[94m + """ % (R, W,R)) diff --git a/utilis.py b/utilis.py new file mode 100644 index 0000000..5bbb941 --- /dev/null +++ b/utilis.py @@ -0,0 +1,95 @@ +import binascii +import gmpy2 + + + +def Convert(decimal): + hex_ = hex(decimal).replace("0x","").replace("L","") + ascii = binascii.a2b_hex(hex_) + print("\nPlainText in Decimal :",decimal) + print("PlainText in hex :",hex_) + print("PlainText in ascii :",ascii.decode("utf-8")) + +def egcd(b, n): + (x0, x1, y0, y1) = (1, 0, 0, 1) + while n != 0: + (q, b, n) = (b // n, n, b % n) + (x0, x1) = (x1, x0 - q * x1) + (y0, y1) = (y1, y0 - q * y1) + return (b, x0, y0) +def modinv(a,m): + g, x, y = egcd(a, m) + if g != 1: + raise Exception('modular inverse does not exist') + else: + return x % m + + +def mul_inv(a, b): + b0 = b + x0, x1 = 0, 1 + if b == 1: return 1 + while a > 1: + q = a // b + a, b = b, a%b + x0, x1 = x1 - q * x0, x0 + if x1 < 0: x1 += b0 + return x1 + +def inv_pow(c, e): + low = -1 + high = c+1 + while low + 1 < high: + m = (low + high) // 2 + p = pow(m, e) + if p < c: + low = m + else: + high = m + m = high + assert pow(m, e) == c + return m +def division_euclidienne(a, b): + return (a // b, a % b) +def fraction_continue(n, d): + developpement = [] + a = n + b = d + while b != 0: + (q,r) = division_euclidienne(a,b) + developpement.append(q) + a = b + b = r + return (developpement) +def reduites_fraction_continue(a): + l=len(a) + reduites=[] + h0 = 1 + h1 = 0 + k0 = 0 + k1 = 1 + count = 0 + while count < l: + h = a[count] * h1 + h0 + h0 = h1 + h1 = h + k = a[count] * k1 + k0 + k0 = k1 + k1 = k + reduites.append((k,h)) + count += 1 + return (reduites) + +def floorSqrt(n): + x = n + y = (x + 1) // 2 + while y < x: + x = y + y = (x + n // x) // 2 + return x + + + + + + From 858601067749bdcb99aeb56ebd307aa8648ad5e7 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:43:49 +0200 Subject: [PATCH 100/122] Add files via upload --- RSA.py | 46 +++++++++++++++++++++++++ RSA2.py | 32 ++++++++++++++++++ RSA3.py | 28 +++++++++++++++ RSA4.py | 23 +++++++++++++ RSA5.py | 58 ++++++++++++++++++++++++++++++++ RSA6.py | 25 ++++++++++++++ RSA7.py | 36 ++++++++++++++++++++ RSA8.py | 26 ++++++++++++++ RSA_chinese_remainder_theorem.py | 32 ++++++++++++++++++ RSA_common_exponent.py | 39 +++++++++++++++++++++ RSA_common_modulus.py | 52 ++++++++++++++++++++++++++++ RSA_hasted.py | 45 +++++++++++++++++++++++++ RSA_multiPrime1.py | 37 ++++++++++++++++++++ RSA_wiener.py | 41 ++++++++++++++++++++++ 14 files changed, 520 insertions(+) create mode 100644 RSA.py create mode 100644 RSA2.py create mode 100644 RSA3.py create mode 100644 RSA4.py create mode 100644 RSA5.py create mode 100644 RSA6.py create mode 100644 RSA7.py create mode 100644 RSA8.py create mode 100644 RSA_chinese_remainder_theorem.py create mode 100644 RSA_common_exponent.py create mode 100644 RSA_common_modulus.py create mode 100644 RSA_hasted.py create mode 100644 RSA_multiPrime1.py create mode 100644 RSA_wiener.py diff --git a/RSA.py b/RSA.py new file mode 100644 index 0000000..4c6c676 --- /dev/null +++ b/RSA.py @@ -0,0 +1,46 @@ +from banner import * +from utilis import egcd,modinv,Convert +from Factorizations.factordb import * +banner() + +""" +# Example : +c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 +n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 +e = 65537 +""" + +try: + + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + + factordb = factordb(n) + q = factordb[0] + p = factordb[1] + phi = (p-1)*(q-1) + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") + slowprint("\n[!] Try To Use MultiPrime Attack ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c, e, n Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except requests.exceptions.ConnectionError: + slowprint("\n[-] Check Your Internet") +except: + slowprint("False Attack") diff --git a/RSA2.py b/RSA2.py new file mode 100644 index 0000000..ff67757 --- /dev/null +++ b/RSA2.py @@ -0,0 +1,32 @@ +from banner import * +from utilis import Convert,modinv +banner() + +""" +c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 +p = 238324208831434331628131715304428889871 +q = 296805874594538235115008173244022912163 +e = 3 +""" + +try: + c = int(input(">>> c = ")) + p = int(input(">>> p = ")) + q = int(input(">>> q = ")) + e = int(input(">>> e = ")) + + n = p*q + phi = (p-1)*(q-1) + d = modinv(e,phi) + m = pow(c,d,n) + Convert(m) + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/RSA3.py b/RSA3.py new file mode 100644 index 0000000..2da1e53 --- /dev/null +++ b/RSA3.py @@ -0,0 +1,28 @@ +from banner import * +from utilis import Convert +banner() + +# Note : Check if phi , n has the same p,q +""" +c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 +n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 +d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 +e = 65537 +phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + d = int(input(">>> d = ")) + e = int(input(">>> e = ")) + phi = int(input(">>> phi = ")) + m = pow(c,d,n) + Convert(m) +except ValueError: + slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/RSA4.py b/RSA4.py new file mode 100644 index 0000000..70d0202 --- /dev/null +++ b/RSA4.py @@ -0,0 +1,23 @@ +from banner import * +from utilis import Convert +banner() +""" +n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 +c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + d = int(input(">>> d = ")) + + m = pow(c,d,n) + Convert(m) +except ValueError: + slowprint("\n[-] c,n,d Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/RSA5.py b/RSA5.py new file mode 100644 index 0000000..03c89e2 --- /dev/null +++ b/RSA5.py @@ -0,0 +1,58 @@ +from banner import * +from utilis import floorSqrt,modinv,Convert +import sympy as sp +banner() + +""" +n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 +e = 65537 +d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 +c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 +""" +def premRSA(n,e,d,c): + bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) + bitLenD0 = 2048 + + assert bitLenD0 >= bitLenN/2 + + d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) + m = pow(c,d,n) + return m + +def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): + test = pow(3, e, n) + test2 = pow(5, e, n) + for k in range(1,e): + d = ((k * n + 1) // e) + d >>= d0BitSize + d <<= d0BitSize + d |= d0 + if((e * d) % k == 1): + if pow(test, d, n) == 3: + if pow(test2, d, n) == 5: + totientN = (e*d - 1) // k + b = totientN - n - 1 + discriminant = b*b - 4*n + root = floorSqrt(discriminant) + if(root*root != discriminant): + continue + p = (-b + root) // 2 + q = n // p + return d + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + d = int(input(">>> d = ")) + m = premRSA(n,e,d,c) + Convert(m) + +except ValueError: + slowprint("\n[-] c,n,d,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA6.py b/RSA6.py new file mode 100644 index 0000000..683d925 --- /dev/null +++ b/RSA6.py @@ -0,0 +1,25 @@ +from banner import * +from utilis import egcd,modinv,Convert +from fractions import Fraction +banner() +""" +p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 +c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 +e = 65537 +n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 +""" +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + p = int(input(">>> p = ")) + print(n) + q = n//p + phi = (p-1) * (q-1) + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/RSA7.py b/RSA7.py new file mode 100644 index 0000000..5d8d183 --- /dev/null +++ b/RSA7.py @@ -0,0 +1,36 @@ +from banner import * +from utilis import egcd,modinv,Convert +import binascii +banner() + +""" +e = 65537 +n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 +dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 +c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + dp = int(input(">>> dp = ")) + mp = (dp * e) - 1 + for i in range(2,1000000): + p = (mp // i) + 1 + if n % p == 0: + break + q = n//p + slowprint("\n[+] Please Wait ... \033[95m\n") + phi = (p-1)*(q-1) + + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) + +except ValueError: + slowprint("\n[-] c,n,e,dp Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/RSA8.py b/RSA8.py new file mode 100644 index 0000000..8e01b87 --- /dev/null +++ b/RSA8.py @@ -0,0 +1,26 @@ +from banner import * +from utilis import Convert +banner() + + + +# Example +#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 + +try: + import gmpy2 + import binascii + c = int(input(">>> c = ")) + m = gmpy2.iroot(c, 3)[0] + assert pow(m,3) == c + Convert(m) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py new file mode 100644 index 0000000..532ecf8 --- /dev/null +++ b/RSA_chinese_remainder_theorem.py @@ -0,0 +1,32 @@ +from banner import * +from utilis import modinv,Convert +banner() +#Example +""" +c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 +p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 +q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 +dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 +dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 +""" +try: + c = int(input(">>> c = ")) + p = int(input(">>> p = ")) + q = int(input(">>> q = ")) + dp = int(input(">>> dp = ")) + dq = int(input(">>> dq = ")) + + slowprint("\n[+] Please Wait ... \033[95m\n") + def chinese_remainder_theorem(p,q,dp,dq,chipher_text): + q_inv = modinv(p , q) + m1 = pow(chipher_text,dp,p) + m2 = pow(chipher_text,dq,q) + h = (q_inv*(m1-m2)) % p + return m2 + h * q + Convert(chinese_remainder_theorem(p,q,dp,dq,c)) +except ValueError: + slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/RSA_common_exponent.py b/RSA_common_exponent.py new file mode 100644 index 0000000..10760fc --- /dev/null +++ b/RSA_common_exponent.py @@ -0,0 +1,39 @@ +from banner import * +from utilis import egcd,modinv,Convert +banner() +""" +n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 +n2 = 10210032872259313686164929473710869592253665432474968016181665104415833992599841926829524498430031021642288824945683044264288937821741278527156550423507713336648261819557381748119064650541556448192793186877429032749223390372405186620392499684387407129200331654256366265932387530132500098451224874600895892420947291972547271991706165603868937708772321221206586800972518013238899316242083977031307714803896630612616326248775444788388309984437812243115218989690016673 +c1 = 66392227979404854586458510145632770314092785183583016343730600866783415262123689751268136986554015242755982639115194608534311988971825645169411730748186710947220673034519486951708550346274786041388143262608730637962604985755406789741345581700390500478433427709495522821473858104289236940045533583368435030007 +c2 = 930631363282343082351877158963544600758567980445720982159124066613164772521801283854718425072511342860751113498013426077785323580215340717638119847338418916957048868138332980175665931485108461262077829550248080371766930777925758187526884947593887945397880426339790518082874861594313920319799945895788141894706108889222173060684161230756671422619830375801046671640406258873119163443168478229210037764301299889548125261094599251838443625348832760001827881979679672 +e = 65537 +""" +n1 = int(input(">>> n1 = ")) +n2 = int(input(">>> n2 = ")) +c1 = int(input(">>> c1 = ")) +c2 = int(input(">>> c2 = ")) +e = int(input(">>> e = ")) + + +if egcd(n1,n2)[0] == 1: + print("[-] Sorry , gcd(n1,n2) = 1") + exit() +else: + 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) + try: + m1 = pow(c1,d1,n1) + Convert(m1) + except TypeError: + pass + try: + m2 = pow(c2,d2,n2) + Convert(m2) + except TypeError: + pass + diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py new file mode 100644 index 0000000..a0407a7 --- /dev/null +++ b/RSA_common_modulus.py @@ -0,0 +1,52 @@ +from banner import * +from utilis import egcd,Convert +banner() +""" +n = 121785996773018308653850214729611957957750585856946607620398279656647965006857599756926384863459274369411103073349913717154710735727786240206066327436155758154142877120260776520601315370480059127244029804523614658953301573686851312721445206131147094674807765817210890772194336025491364961932882951123597124291 +e2 = 343223 +c2 = 99993713982446651581396992055360571139557381122865583938229634474666415937105325664345678113405954865343401854091338680448775405253508255042453184099961570780032181898606546389573694481401653361757628850127420072609555997892925890632116852740542002226555293049123266123721696951805937683483979653786235824108 +e1 = 65537 +c1 = 5050983197907648139720782448847677677343236446273586870502111273113384857588837608900494692102715861436825279596563904392832518247929761994240007673498974877828278590361242528762459283022987952424770766975922016521475963712698089809426428406068793291250622593222599407825968002220906973019105007856539702124 +""" +try: + import gmpy2 + from Crypto.Util.number import GCD + + def neg_pow(a, b, n): + assert b < 0 + assert GCD(a, n) == 1 + res = int(gmpy2.invert(a, n)) + res = pow(res, b*(-1), n) + return res + + def common_modulus(e1, e2, n, c1, c2): + g, a, b = egcd(e1, e2) + if a < 0: + c1 = neg_pow(c1, a, n) + else: + c1 = pow(c1, a, n) + if b < 0: + c2 = neg_pow(c2, b, n) + else: + c2 = pow(c2, b, n) + ct = c1*c2 % n + m = int(gmpy2.iroot(ct, g)[0]) + return m + """ + c1 = int(input(">>> c1 = ")) + c2 = int(input(">>> c2 = ")) + e1 = int(input(">>> e1 = ")) + e2 = int(input(">>> e2 = ")) + n = int(input(">>> n = ")) + """ + Convert(common_modulus(e1, e2, n, c1, c2)) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/RSA_hasted.py b/RSA_hasted.py new file mode 100644 index 0000000..640f62c --- /dev/null +++ b/RSA_hasted.py @@ -0,0 +1,45 @@ +from banner import * +from utilis import inv_pow,mul_inv,Convert +import functools +banner() + +""" +N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 +C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 +N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 +C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 +N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 +C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 +""" + + +def chinese_remainder(n, a): + sum = 0 + prod = functools.reduce(lambda a, b: a*b, n) + for n_i, a_i in zip(n, a): + p = prod // n_i + sum += a_i * mul_inv(p, n_i) * p + return sum % prod + +try: + C1 = int(raw_input(">>> c1 = ")) + C2 = int(raw_input(">>> c2 = ")) + C3 = int(raw_input(">>> c3 = ")) + N1 = int(raw_input(">>> n1 = ")) + N2 = int(raw_input(">>> n2 = ")) + N3 = int(raw_input(">>> n3 = ")) + + N = [N1, N2, N3] + C = [C1, C2, C3] + e = len(N) + a = chinese_remainder(N, C) + for n, c in zip(N, C): + assert a % n == c + m = inv_pow(a, e) + Convert(m) +except ValueError: + slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py new file mode 100644 index 0000000..88cd411 --- /dev/null +++ b/RSA_multiPrime1.py @@ -0,0 +1,37 @@ +from banner import * +from utilis import egcd,modinv,Convert +from Factorizations.ecm import * +banner() + +""" +c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 +n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 +e= 65537 +prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] +""" + +try: + + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + prime = primefactors(n) + + phi = 1 + for i in prime: + phi *= i-1 + + d = modinv(e, phi) + m = pow(c, d, n) + Convert(m) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,n,e Must Be Integar Number") +except KeyboardInterrupt: + exit() +except: + slowprint("[-] False Attack !") diff --git a/RSA_wiener.py b/RSA_wiener.py new file mode 100644 index 0000000..28aa036 --- /dev/null +++ b/RSA_wiener.py @@ -0,0 +1,41 @@ +from banner import * +from utilis import reduites_fraction_continue,fraction_continue,division_euclidienne,Convert +import random +banner() + +""" +#Example : +n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 +c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 +""" + +try: + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + + def wiener(n, e): + fc = fraction_continue(e, n) + reduites = reduites_fraction_continue(fc) + message_clair = random.randint(10**1,10**5) + message_chiffre = pow(message_clair, e, n) + l = len(reduites) + i = 0 + while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: + i += 1 + if i != l: + return (reduites[i][1]) + else: + print("[-] Sorry it's Not Wiener Attack\n") + exit(0) + + d = wiener(n,e) + print("\nd = ",d) + c = int(input(">>> c = ")) + decode = pow(c,d,n) + Convert(decode) + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") From 0b6581d5517eae28af9d3d28ff81a70efbc11552 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:44:04 +0200 Subject: [PATCH 101/122] Delete a --- Attacks/a | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Attacks/a diff --git a/Attacks/a b/Attacks/a deleted file mode 100644 index 8b13789..0000000 --- a/Attacks/a +++ /dev/null @@ -1 +0,0 @@ - From 1f39b1a0c0f0b042ba658a412bc24eddf0809378 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:01 +0200 Subject: [PATCH 102/122] Delete RSA.py --- RSA.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 RSA.py diff --git a/RSA.py b/RSA.py deleted file mode 100644 index 4c6c676..0000000 --- a/RSA.py +++ /dev/null @@ -1,46 +0,0 @@ -from banner import * -from utilis import egcd,modinv,Convert -from Factorizations.factordb import * -banner() - -""" -# Example : -c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 -n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 -e = 65537 -""" - -try: - - def factordb(n): - f = FactorDB(n) - f.connect() - return f.get_factor_list() - - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - - factordb = factordb(n) - q = factordb[0] - p = factordb[1] - phi = (p-1)*(q-1) - d = modinv(e,phi) - decode = pow(c,d,n) - Convert(decode) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n ") - slowprint("\n[!] Try To Use MultiPrime Attack ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c, e, n Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except requests.exceptions.ConnectionError: - slowprint("\n[-] Check Your Internet") -except: - slowprint("False Attack") From 17982789b4e23ea55fd1dba881e9ef581033109b Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:04 +0200 Subject: [PATCH 103/122] Delete RSA2.py --- RSA2.py | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 RSA2.py diff --git a/RSA2.py b/RSA2.py deleted file mode 100644 index ff67757..0000000 --- a/RSA2.py +++ /dev/null @@ -1,32 +0,0 @@ -from banner import * -from utilis import Convert,modinv -banner() - -""" -c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 -p = 238324208831434331628131715304428889871 -q = 296805874594538235115008173244022912163 -e = 3 -""" - -try: - c = int(input(">>> c = ")) - p = int(input(">>> p = ")) - q = int(input(">>> q = ")) - e = int(input(">>> e = ")) - - n = p*q - phi = (p-1)*(q-1) - d = modinv(e,phi) - m = pow(c,d,n) - Convert(m) - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() - From 80cebe5aba8fe6c2ae3f11b24a92f35f9aa47b41 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:18 +0200 Subject: [PATCH 104/122] Delete RSA3.py --- RSA3.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 RSA3.py diff --git a/RSA3.py b/RSA3.py deleted file mode 100644 index 2da1e53..0000000 --- a/RSA3.py +++ /dev/null @@ -1,28 +0,0 @@ -from banner import * -from utilis import Convert -banner() - -# Note : Check if phi , n has the same p,q -""" -c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 -n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 -d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 -e = 65537 -phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 -""" - -try: - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - d = int(input(">>> d = ")) - e = int(input(">>> e = ")) - phi = int(input(">>> phi = ")) - m = pow(c,d,n) - Convert(m) -except ValueError: - slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() - From 4d44e9ec1e9701f2b1929c4d4b004db536d63e85 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:20 +0200 Subject: [PATCH 105/122] Delete RSA4.py --- RSA4.py | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 RSA4.py diff --git a/RSA4.py b/RSA4.py deleted file mode 100644 index 70d0202..0000000 --- a/RSA4.py +++ /dev/null @@ -1,23 +0,0 @@ -from banner import * -from utilis import Convert -banner() -""" -n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 -c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 -""" - -try: - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - d = int(input(">>> d = ")) - - m = pow(c,d,n) - Convert(m) -except ValueError: - slowprint("\n[-] c,n,d Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() - From 4e6816e47eb5164aa88d473b1422b6a886de6ffe Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:22 +0200 Subject: [PATCH 106/122] Delete RSA5.py --- RSA5.py | 58 --------------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 RSA5.py diff --git a/RSA5.py b/RSA5.py deleted file mode 100644 index 03c89e2..0000000 --- a/RSA5.py +++ /dev/null @@ -1,58 +0,0 @@ -from banner import * -from utilis import floorSqrt,modinv,Convert -import sympy as sp -banner() - -""" -n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 -e = 65537 -d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 -c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 -""" -def premRSA(n,e,d,c): - bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) - bitLenD0 = 2048 - - assert bitLenD0 >= bitLenN/2 - - d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) - m = pow(c,d,n) - return m - -def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): - test = pow(3, e, n) - test2 = pow(5, e, n) - for k in range(1,e): - d = ((k * n + 1) // e) - d >>= d0BitSize - d <<= d0BitSize - d |= d0 - if((e * d) % k == 1): - if pow(test, d, n) == 3: - if pow(test2, d, n) == 5: - totientN = (e*d - 1) // k - b = totientN - n - 1 - discriminant = b*b - 4*n - root = floorSqrt(discriminant) - if(root*root != discriminant): - continue - p = (-b + root) // 2 - q = n // p - return d - -try: - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - d = int(input(">>> d = ")) - m = premRSA(n,e,d,c) - Convert(m) - -except ValueError: - slowprint("\n[-] c,n,d,e Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 60e0dc473cc4e7c641667a3e3f38adf6820c4216 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:25 +0200 Subject: [PATCH 107/122] Delete RSA6.py --- RSA6.py | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 RSA6.py diff --git a/RSA6.py b/RSA6.py deleted file mode 100644 index 683d925..0000000 --- a/RSA6.py +++ /dev/null @@ -1,25 +0,0 @@ -from banner import * -from utilis import egcd,modinv,Convert -from fractions import Fraction -banner() -""" -p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 -c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 -e = 65537 -n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 -""" -try: - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - p = int(input(">>> p = ")) - print(n) - q = n//p - phi = (p-1) * (q-1) - d = modinv(e,phi) - decode = pow(c,d,n) - Convert(decode) -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() From a1faeb61b70a6394c9ffbcd2f25f51f08552ca2f Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:27 +0200 Subject: [PATCH 108/122] Delete RSA7.py --- RSA7.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 RSA7.py diff --git a/RSA7.py b/RSA7.py deleted file mode 100644 index 5d8d183..0000000 --- a/RSA7.py +++ /dev/null @@ -1,36 +0,0 @@ -from banner import * -from utilis import egcd,modinv,Convert -import binascii -banner() - -""" -e = 65537 -n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 -dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 -c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 -""" - -try: - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - dp = int(input(">>> dp = ")) - mp = (dp * e) - 1 - for i in range(2,1000000): - p = (mp // i) + 1 - if n % p == 0: - break - q = n//p - slowprint("\n[+] Please Wait ... \033[95m\n") - phi = (p-1)*(q-1) - - d = modinv(e,phi) - decode = pow(c,d,n) - Convert(decode) - -except ValueError: - slowprint("\n[-] c,n,e,dp Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() From cdd42c25e8c1155fc797faebec1d848286005d40 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:46 +0200 Subject: [PATCH 109/122] Delete RSA8.py --- RSA8.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 RSA8.py diff --git a/RSA8.py b/RSA8.py deleted file mode 100644 index 8e01b87..0000000 --- a/RSA8.py +++ /dev/null @@ -1,26 +0,0 @@ -from banner import * -from utilis import Convert -banner() - - - -# Example -#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 - -try: - import gmpy2 - import binascii - c = int(input(">>> c = ")) - m = gmpy2.iroot(c, 3)[0] - assert pow(m,3) == c - Convert(m) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From b1f1fd373b73f4426656e40f4492ae2ba9c75a7f Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:48 +0200 Subject: [PATCH 110/122] Delete RSA_chinese_remainder_theorem.py --- RSA_chinese_remainder_theorem.py | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 RSA_chinese_remainder_theorem.py diff --git a/RSA_chinese_remainder_theorem.py b/RSA_chinese_remainder_theorem.py deleted file mode 100644 index 532ecf8..0000000 --- a/RSA_chinese_remainder_theorem.py +++ /dev/null @@ -1,32 +0,0 @@ -from banner import * -from utilis import modinv,Convert -banner() -#Example -""" -c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 -p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 -q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 -dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 -dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 -""" -try: - c = int(input(">>> c = ")) - p = int(input(">>> p = ")) - q = int(input(">>> q = ")) - dp = int(input(">>> dp = ")) - dq = int(input(">>> dq = ")) - - slowprint("\n[+] Please Wait ... \033[95m\n") - def chinese_remainder_theorem(p,q,dp,dq,chipher_text): - q_inv = modinv(p , q) - m1 = pow(chipher_text,dp,p) - m2 = pow(chipher_text,dq,q) - h = (q_inv*(m1-m2)) % p - return m2 + h * q - Convert(chinese_remainder_theorem(p,q,dp,dq,c)) -except ValueError: - slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() From 8ba1ed0cf73881260a813eeb1a764d2b99244a19 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:51 +0200 Subject: [PATCH 111/122] Delete RSA_common_exponent.py --- RSA_common_exponent.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 RSA_common_exponent.py diff --git a/RSA_common_exponent.py b/RSA_common_exponent.py deleted file mode 100644 index 10760fc..0000000 --- a/RSA_common_exponent.py +++ /dev/null @@ -1,39 +0,0 @@ -from banner import * -from utilis import egcd,modinv,Convert -banner() -""" -n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 -n2 = 10210032872259313686164929473710869592253665432474968016181665104415833992599841926829524498430031021642288824945683044264288937821741278527156550423507713336648261819557381748119064650541556448192793186877429032749223390372405186620392499684387407129200331654256366265932387530132500098451224874600895892420947291972547271991706165603868937708772321221206586800972518013238899316242083977031307714803896630612616326248775444788388309984437812243115218989690016673 -c1 = 66392227979404854586458510145632770314092785183583016343730600866783415262123689751268136986554015242755982639115194608534311988971825645169411730748186710947220673034519486951708550346274786041388143262608730637962604985755406789741345581700390500478433427709495522821473858104289236940045533583368435030007 -c2 = 930631363282343082351877158963544600758567980445720982159124066613164772521801283854718425072511342860751113498013426077785323580215340717638119847338418916957048868138332980175665931485108461262077829550248080371766930777925758187526884947593887945397880426339790518082874861594313920319799945895788141894706108889222173060684161230756671422619830375801046671640406258873119163443168478229210037764301299889548125261094599251838443625348832760001827881979679672 -e = 65537 -""" -n1 = int(input(">>> n1 = ")) -n2 = int(input(">>> n2 = ")) -c1 = int(input(">>> c1 = ")) -c2 = int(input(">>> c2 = ")) -e = int(input(">>> e = ")) - - -if egcd(n1,n2)[0] == 1: - print("[-] Sorry , gcd(n1,n2) = 1") - exit() -else: - 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) - try: - m1 = pow(c1,d1,n1) - Convert(m1) - except TypeError: - pass - try: - m2 = pow(c2,d2,n2) - Convert(m2) - except TypeError: - pass - From 0f3700c3d31768c618351212bca90c0bc8360216 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:53 +0200 Subject: [PATCH 112/122] Delete RSA_common_modulus.py --- RSA_common_modulus.py | 52 ------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 RSA_common_modulus.py diff --git a/RSA_common_modulus.py b/RSA_common_modulus.py deleted file mode 100644 index a0407a7..0000000 --- a/RSA_common_modulus.py +++ /dev/null @@ -1,52 +0,0 @@ -from banner import * -from utilis import egcd,Convert -banner() -""" -n = 121785996773018308653850214729611957957750585856946607620398279656647965006857599756926384863459274369411103073349913717154710735727786240206066327436155758154142877120260776520601315370480059127244029804523614658953301573686851312721445206131147094674807765817210890772194336025491364961932882951123597124291 -e2 = 343223 -c2 = 99993713982446651581396992055360571139557381122865583938229634474666415937105325664345678113405954865343401854091338680448775405253508255042453184099961570780032181898606546389573694481401653361757628850127420072609555997892925890632116852740542002226555293049123266123721696951805937683483979653786235824108 -e1 = 65537 -c1 = 5050983197907648139720782448847677677343236446273586870502111273113384857588837608900494692102715861436825279596563904392832518247929761994240007673498974877828278590361242528762459283022987952424770766975922016521475963712698089809426428406068793291250622593222599407825968002220906973019105007856539702124 -""" -try: - import gmpy2 - from Crypto.Util.number import GCD - - def neg_pow(a, b, n): - assert b < 0 - assert GCD(a, n) == 1 - res = int(gmpy2.invert(a, n)) - res = pow(res, b*(-1), n) - return res - - def common_modulus(e1, e2, n, c1, c2): - g, a, b = egcd(e1, e2) - if a < 0: - c1 = neg_pow(c1, a, n) - else: - c1 = pow(c1, a, n) - if b < 0: - c2 = neg_pow(c2, b, n) - else: - c2 = pow(c2, b, n) - ct = c1*c2 % n - m = int(gmpy2.iroot(ct, g)[0]) - return m - """ - c1 = int(input(">>> c1 = ")) - c2 = int(input(">>> c2 = ")) - e1 = int(input(">>> e1 = ")) - e2 = int(input(">>> e2 = ")) - n = int(input(">>> n = ")) - """ - Convert(common_modulus(e1, e2, n, c1, c2)) -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() -except: - slowprint("\n[-] False Attack !") From 1c5ecefda2d407b308a62f15020e29b794dad4db Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:55 +0200 Subject: [PATCH 113/122] Delete RSA_hasted.py --- RSA_hasted.py | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 RSA_hasted.py diff --git a/RSA_hasted.py b/RSA_hasted.py deleted file mode 100644 index 640f62c..0000000 --- a/RSA_hasted.py +++ /dev/null @@ -1,45 +0,0 @@ -from banner import * -from utilis import inv_pow,mul_inv,Convert -import functools -banner() - -""" -N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 -C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 -N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 -C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 -N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 -C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 -""" - - -def chinese_remainder(n, a): - sum = 0 - prod = functools.reduce(lambda a, b: a*b, n) - for n_i, a_i in zip(n, a): - p = prod // n_i - sum += a_i * mul_inv(p, n_i) * p - return sum % prod - -try: - C1 = int(raw_input(">>> c1 = ")) - C2 = int(raw_input(">>> c2 = ")) - C3 = int(raw_input(">>> c3 = ")) - N1 = int(raw_input(">>> n1 = ")) - N2 = int(raw_input(">>> n2 = ")) - N3 = int(raw_input(">>> n3 = ")) - - N = [N1, N2, N3] - C = [C1, C2, C3] - e = len(N) - a = chinese_remainder(N, C) - for n, c in zip(N, C): - assert a % n == c - m = inv_pow(a, e) - Convert(m) -except ValueError: - slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") -except AssertionError: - slowprint("\n[-] Wrong Data") -except KeyboardInterrupt: - exit() From eb87caaf55db3f01d54c10cf0fed14848b59494f Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:45:58 +0200 Subject: [PATCH 114/122] Delete RSA_multiPrime1.py --- RSA_multiPrime1.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 RSA_multiPrime1.py diff --git a/RSA_multiPrime1.py b/RSA_multiPrime1.py deleted file mode 100644 index 88cd411..0000000 --- a/RSA_multiPrime1.py +++ /dev/null @@ -1,37 +0,0 @@ -from banner import * -from utilis import egcd,modinv,Convert -from Factorizations.ecm import * -banner() - -""" -c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 -n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 -e= 65537 -prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] -""" - -try: - - c = int(input(">>> c = ")) - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - prime = primefactors(n) - - phi = 1 - for i in prime: - phi *= i-1 - - d = modinv(e, phi) - m = pow(c, d, n) - Convert(m) - -except IndexError: - slowprint("[-] Sorry Can't Factorize n ") -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,n,e Must Be Integar Number") -except KeyboardInterrupt: - exit() -except: - slowprint("[-] False Attack !") From c15e1c6f91f9c00f2b37358892fa3f5a68600816 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:46:00 +0200 Subject: [PATCH 115/122] Delete RSA_wiener.py --- RSA_wiener.py | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 RSA_wiener.py diff --git a/RSA_wiener.py b/RSA_wiener.py deleted file mode 100644 index 28aa036..0000000 --- a/RSA_wiener.py +++ /dev/null @@ -1,41 +0,0 @@ -from banner import * -from utilis import reduites_fraction_continue,fraction_continue,division_euclidienne,Convert -import random -banner() - -""" -#Example : -n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 -e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 -c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 -""" - -try: - n = int(input(">>> n = ")) - e = int(input(">>> e = ")) - - def wiener(n, e): - fc = fraction_continue(e, n) - reduites = reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - return (reduites[i][1]) - else: - print("[-] Sorry it's Not Wiener Attack\n") - exit(0) - - d = wiener(n,e) - print("\nd = ",d) - c = int(input(">>> c = ")) - decode = pow(c,d,n) - Convert(decode) - -except ImportError: - slowprint("\n[-] Module Not Setup") -except ValueError: - slowprint("\n[-] c,p,q,e Must Be Integar Number") From 39e84732bd20088cc7357edb107cccbdaade89ce Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:46:18 +0200 Subject: [PATCH 116/122] Create s --- Attacks/s | 1 + 1 file changed, 1 insertion(+) create mode 100644 Attacks/s diff --git a/Attacks/s b/Attacks/s new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Attacks/s @@ -0,0 +1 @@ + From a89d02f2adc233a96cbe5debfe904c1945382c07 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:46:58 +0200 Subject: [PATCH 117/122] Add files via upload --- Attacks/RSA.py | 46 +++++++++++++++++++ Attacks/RSA2.py | 32 +++++++++++++ Attacks/RSA3.py | 28 ++++++++++++ Attacks/RSA4.py | 23 ++++++++++ Attacks/RSA5.py | 58 ++++++++++++++++++++++++ Attacks/RSA6.py | 25 ++++++++++ Attacks/RSA7.py | 36 +++++++++++++++ Attacks/RSA8.py | 26 +++++++++++ Attacks/RSA_chinese_remainder_theorem.py | 32 +++++++++++++ Attacks/RSA_common_exponent.py | 39 ++++++++++++++++ Attacks/RSA_common_modulus.py | 52 +++++++++++++++++++++ Attacks/RSA_hasted.py | 45 ++++++++++++++++++ Attacks/RSA_multiPrime1.py | 37 +++++++++++++++ Attacks/RSA_wiener.py | 41 +++++++++++++++++ 14 files changed, 520 insertions(+) create mode 100644 Attacks/RSA.py create mode 100644 Attacks/RSA2.py create mode 100644 Attacks/RSA3.py create mode 100644 Attacks/RSA4.py create mode 100644 Attacks/RSA5.py create mode 100644 Attacks/RSA6.py create mode 100644 Attacks/RSA7.py create mode 100644 Attacks/RSA8.py create mode 100644 Attacks/RSA_chinese_remainder_theorem.py create mode 100644 Attacks/RSA_common_exponent.py create mode 100644 Attacks/RSA_common_modulus.py create mode 100644 Attacks/RSA_hasted.py create mode 100644 Attacks/RSA_multiPrime1.py create mode 100644 Attacks/RSA_wiener.py diff --git a/Attacks/RSA.py b/Attacks/RSA.py new file mode 100644 index 0000000..4c6c676 --- /dev/null +++ b/Attacks/RSA.py @@ -0,0 +1,46 @@ +from banner import * +from utilis import egcd,modinv,Convert +from Factorizations.factordb import * +banner() + +""" +# Example : +c = 194048013822218245260658018019940874060627700835842604475987702337533801266490182061968998210807564778328557627772974110046885380635225974269865976518335375789734689098164529086561756412074742698644530189076800227300946408167039318949544794351233987752575608106800908043533012088081995031010618521695843625062 +n = 248501410365662412791489552646042256782092770118253438700194718631291036762726489658495565276550205113648626040596191969135846656414394584577305526761671104277390765264806022908497647300596494542202565022133435383403344333672279722534625284520459706609569974491538689429548817677759350947931780871046796607829 +e = 65537 +""" + +try: + + def factordb(n): + f = FactorDB(n) + f.connect() + return f.get_factor_list() + + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + + factordb = factordb(n) + q = factordb[0] + p = factordb[1] + phi = (p-1)*(q-1) + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") + slowprint("\n[!] Try To Use MultiPrime Attack ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c, e, n Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except requests.exceptions.ConnectionError: + slowprint("\n[-] Check Your Internet") +except: + slowprint("False Attack") diff --git a/Attacks/RSA2.py b/Attacks/RSA2.py new file mode 100644 index 0000000..ff67757 --- /dev/null +++ b/Attacks/RSA2.py @@ -0,0 +1,32 @@ +from banner import * +from utilis import Convert,modinv +banner() + +""" +c = 29846947519214575162497413725060412546119233216851184246267357770082463030225 +p = 238324208831434331628131715304428889871 +q = 296805874594538235115008173244022912163 +e = 3 +""" + +try: + c = int(input(">>> c = ")) + p = int(input(">>> p = ")) + q = int(input(">>> q = ")) + e = int(input(">>> e = ")) + + n = p*q + phi = (p-1)*(q-1) + d = modinv(e,phi) + m = pow(c,d,n) + Convert(m) + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/Attacks/RSA3.py b/Attacks/RSA3.py new file mode 100644 index 0000000..2da1e53 --- /dev/null +++ b/Attacks/RSA3.py @@ -0,0 +1,28 @@ +from banner import * +from utilis import Convert +banner() + +# Note : Check if phi , n has the same p,q +""" +c = 37209877026138824302301697292319328185824059912506644719041273895972747926698556612194455367172368277268883774102719113194850674012999971337550561061697826458468363574428378679179721672530515881761949297613967812683948622068020382771205609975220407119022966600675469044732891210789248284410739482876937857726026431593283960162298707892143970513804892248370427455318472402011536095802255121284911517882268092785246985981687913310965628793178703498961617628661113277249071490584774764571170891391355080033791745662119139170834529306548644716069025161989103880671580075279656495472299747401794635781847901588156099495017 +n = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678462101261445039900408999429969510786960471887158957679337190091527913340383310225813322177657695256994315048270952315001100548949554323965404643005206732777361386623591544461533797263652780595639288158892122219626720481472616420118039436680647298714768071797941290307081010086729667552569828323354008441335674251 +d = 36745622940545343875759976434157197886755506358760982257308567037006074391719705315666781200065625116203199598633622026070492775743618607966652393996419663853350085914252797887742782661594880295499227386075929594641556658033207382848075073319786244161193801795105901007640174254798831863226544268004149920625395925259715625248417078457317167458592444532825039828013768181860349705192246622240475711133444054985367520564542488697167606480838294747710396401026533820191299116891186474240520253953309474166963956334430798860084072450328931700881244717326902973061667440442315315084591766881188371668945135391290476758145 +e = 65537 +phi = 43210326036290106251088810298667915702007744567467854988107937233622821671752930583378558808381197036542903396534337305723496107154050324953536530993744267386008120658910242143992656773360792182698142273761182047011119261779988377408208858109503177413194541524543447827777831409903664749520527375514748678461684001179681025836243272641520046001108394411608315423967170123709569701951917513847951924936347574671212789694222728087028519090194131250999358518159691864169187723815719657688598576820104123456547706995794001020837756695923476582226622677087727699446323459489485731800382017980557710365098279949382831681952 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + d = int(input(">>> d = ")) + e = int(input(">>> e = ")) + phi = int(input(">>> phi = ")) + m = pow(c,d,n) + Convert(m) +except ValueError: + slowprint("\n[-] c,n,d,e,phi Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/Attacks/RSA4.py b/Attacks/RSA4.py new file mode 100644 index 0000000..70d0202 --- /dev/null +++ b/Attacks/RSA4.py @@ -0,0 +1,23 @@ +from banner import * +from utilis import Convert +banner() +""" +n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +d = 108642162821084938181507878056324903120999504739411128372202198922197750954973 +c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + d = int(input(">>> d = ")) + + m = pow(c,d,n) + Convert(m) +except ValueError: + slowprint("\n[-] c,n,d Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + diff --git a/Attacks/RSA5.py b/Attacks/RSA5.py new file mode 100644 index 0000000..03c89e2 --- /dev/null +++ b/Attacks/RSA5.py @@ -0,0 +1,58 @@ +from banner import * +from utilis import floorSqrt,modinv,Convert +import sympy as sp +banner() + +""" +n = 441702548375597546265397060347208952276967475274905135912477869560482177333510361384285033947480946188145623354029215951664169885735094097025317925522966956898965174945445544364452506966796499944587005657873812585848386501149925011035458189838748181551356757610548391767844207725796544451539421763642181449329080300719368344152034024278647417306053843499995586981318017650558507022155655502745770884654996618443849292140572931614016663705074656028412717677339714961533961375052773639815540324868758969940933964991941461245158471917647200963814004656567184986255121144463936821101981682767655530654441359046234900674147458678928268719664791590208181725402425003322043157763682685830046581059368233541228450498829982145850640255968763746232611610641869191302389245779111356909617313529277007241602005067848947949307502548984897136138368091937447795052112684321369869694696022995282137270503420632588160475186971207198459134307608759756767731733884585073817881348559945137106821730698056732508316693757300672313883162959195685130393016049081156405669205548223148112949446059403857423978820671852027526778494740114169769151540080734651779260084907492653816632846142736609605163394526211986727369288330063666919831047575220019292555559557 +e = 65537 +d = 20929658227875938261058725840264131720240194797254721497929999366502087574029656881231720165783065592372637815940915666212613039099487922843233911353847485450062009142435445746729639472299106954973763080234456847113054478990804619551767588431261008218457316621723802599302359261042715498257923026077002571619206016545993843650901654469988654046781302853813921776892035397733517301594459235978192450212096281249109282450379464222318996342527212038893311335406614944259596938858799625134827471785811994514192796802507658154603626182055262115513322362471136252282318391917574551672482430283925389405151320872665308738881 +c = 223986220247071217870216666779014143338794244806897003439570261828585609461069625566993441707552858342245944642945164681672765137831785039339186019388055221324788275090628463675778644169814393286912058814837219760390476510773975243291075922094945253348123263684444264887680045467214228402806502985409400661033608167210517145287411533259812656955874094033211161421678440562053003042479607653554525213535393053262147643051962890823534380167045346153321162009201462563059751490608169219660707113678434438625268806729271472128212898965284892857326073914569265528121606803508514214189119223383833552072586814770466728871437446190820676075097507547134736007108263775508884871752392084557481102147503606249246354860813514035927154754953172611572565854652996865901035897405554136502508927222416891115275427864126981053248969607448749019664721233739296140343775145313825978714021202368146466869500962807323607852112530742349058090066478686837929805776585570594765868633295031229876778165218553418581369590926767847888849449544777172583513049998378026545824378239267780173494553559807077301106319453742180763436936829925045341906074598727300955137592558540978215844567601254095649299172760605263652690076724946138284654947266095386055238602230 +""" +def premRSA(n,e,d,c): + bitLenN = int(sp.floor(sp.log(n)/sp.log(2)) + 1) + bitLenD0 = 2048 + + assert bitLenD0 >= bitLenN/2 + + d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) + m = pow(c,d,n) + return m + +def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): + test = pow(3, e, n) + test2 = pow(5, e, n) + for k in range(1,e): + d = ((k * n + 1) // e) + d >>= d0BitSize + d <<= d0BitSize + d |= d0 + if((e * d) % k == 1): + if pow(test, d, n) == 3: + if pow(test2, d, n) == 5: + totientN = (e*d - 1) // k + b = totientN - n - 1 + discriminant = b*b - 4*n + root = floorSqrt(discriminant) + if(root*root != discriminant): + continue + p = (-b + root) // 2 + q = n // p + return d + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + d = int(input(">>> d = ")) + m = premRSA(n,e,d,c) + Convert(m) + +except ValueError: + slowprint("\n[-] c,n,d,e Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/Attacks/RSA6.py b/Attacks/RSA6.py new file mode 100644 index 0000000..683d925 --- /dev/null +++ b/Attacks/RSA6.py @@ -0,0 +1,25 @@ +from banner import * +from utilis import egcd,modinv,Convert +from fractions import Fraction +banner() +""" +p = 153143042272527868798412612417204434156935146874282990942386694020462861918068684561281763577034706600608387699148071015194725533394126069826857182428660427818277378724977554365910231524827258160904493774748749088477328204812171935987088715261127321911849092207070653272176072509933245978935455542420691737433 +c = 14699632914289984358210582075909309608817619615764122409514577850253033131275996955127394794512801987443786025277031557775238937388086632327611216460613138074110905840487213116627139558528011448028813522809156509374602431319619052803531008581645459969997969897966475478980398396687104746302415391434104278327526947341073215599683555703818611403510483832532921625745935543818100178607417658929607435582550913918895885596025822532531372429301293588416086854338617700672628239475365045267537032531973594689061842791028000992635092519215619497247452814483357403667400283975070444902253349175045305073603687442947532925780 +e = 65537 +n = 23952937352643527451379227516428377705004894508566304313177880191662177061878993798938496818120987817049538365206671401938265663712351239785237507341311858383628932183083145614696585411921662992078376103990806989257289472590902167457302888198293135333083734504191910953238278860923153746261500759411620299864395158783509535039259714359526738924736952759753503357614939203434092075676169179112452620687731670534906069845965633455748606649062394293289967059348143206600765820021392608270528856238306849191113241355842396325210132358046616312901337987464473799040762271876389031455051640937681745409057246190498795697239 +""" +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + p = int(input(">>> p = ")) + print(n) + q = n//p + phi = (p-1) * (q-1) + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/Attacks/RSA7.py b/Attacks/RSA7.py new file mode 100644 index 0000000..5d8d183 --- /dev/null +++ b/Attacks/RSA7.py @@ -0,0 +1,36 @@ +from banner import * +from utilis import egcd,modinv,Convert +import binascii +banner() + +""" +e = 65537 +n = 642313240848064014975043934308658242447312485152342673610756859535090103704610472004913349502648157091104463303511131278665176160214474038294042375555935567033107229886104534241324327133387923226576002115108963521725703773387678635509903034467838260875686083768549775481391190161412646384559222421917626615323 +dp = 17765378008759755288183210466105878526943875374957170036175281330288884608317141953683920408636506981101765935449140323585600732241535721917282237462133813 +c = 147903288008907053469880199469959588903705520519775597541160700501753344741954421604588338524905987922631822425828587114084662512860181022047137469441292833823381362238861070683420786510831001513730638949486694641768638258876688738949817816449109334961820861920165271653627904957302093274915248851406573361863 +""" + +try: + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + dp = int(input(">>> dp = ")) + mp = (dp * e) - 1 + for i in range(2,1000000): + p = (mp // i) + 1 + if n % p == 0: + break + q = n//p + slowprint("\n[+] Please Wait ... \033[95m\n") + phi = (p-1)*(q-1) + + d = modinv(e,phi) + decode = pow(c,d,n) + Convert(decode) + +except ValueError: + slowprint("\n[-] c,n,e,dp Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/Attacks/RSA8.py b/Attacks/RSA8.py new file mode 100644 index 0000000..8e01b87 --- /dev/null +++ b/Attacks/RSA8.py @@ -0,0 +1,26 @@ +from banner import * +from utilis import Convert +banner() + + + +# Example +#c = 74802199268254280440493690700608296874229186682164386879225634595063352871356558051619716745745659385094914838131944342112615526475056433710891149995541243955498341403563518984577892267288643941 + +try: + import gmpy2 + import binascii + c = int(input(">>> c = ")) + m = gmpy2.iroot(c, 3)[0] + assert pow(m,3) == c + Convert(m) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/Attacks/RSA_chinese_remainder_theorem.py b/Attacks/RSA_chinese_remainder_theorem.py new file mode 100644 index 0000000..532ecf8 --- /dev/null +++ b/Attacks/RSA_chinese_remainder_theorem.py @@ -0,0 +1,32 @@ +from banner import * +from utilis import modinv,Convert +banner() +#Example +""" +c = 62078086677416686867183857957350338314446280912673392448065026850212685326551183962056495964579782325302082054393933682265772802750887293602432512967994805549965020916953644635965916607925335639027579187435180607475963322465417758959002385451863122106487834784688029167720175128082066670945625067803812970871 +p = 7901324502264899236349230781143813838831920474669364339844939631481665770635584819958931021644265960578585153616742963330195946431321644921572803658406281 +q = 12802918451444044622583757703752066118180068668479378778928741088302355425977192996799623998720429594346778865275391307730988819243843851683079000293815051 +dp = 5540655028622021934429306287937775291955623308965208384582009857376053583575510784169616065113641391169613969813652523507421157045377898542386933198269451 +dq = 9066897320308834206952359399737747311983309062764178906269475847173966073567988170415839954996322314157438770225952491560052871464136163421892050057498651 +""" +try: + c = int(input(">>> c = ")) + p = int(input(">>> p = ")) + q = int(input(">>> q = ")) + dp = int(input(">>> dp = ")) + dq = int(input(">>> dq = ")) + + slowprint("\n[+] Please Wait ... \033[95m\n") + def chinese_remainder_theorem(p,q,dp,dq,chipher_text): + q_inv = modinv(p , q) + m1 = pow(chipher_text,dp,p) + m2 = pow(chipher_text,dq,q) + h = (q_inv*(m1-m2)) % p + return m2 + h * q + Convert(chinese_remainder_theorem(p,q,dp,dq,c)) +except ValueError: + slowprint("\n[-] c,p,q,dp,dq Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/Attacks/RSA_common_exponent.py b/Attacks/RSA_common_exponent.py new file mode 100644 index 0000000..10760fc --- /dev/null +++ b/Attacks/RSA_common_exponent.py @@ -0,0 +1,39 @@ +from banner import * +from utilis import egcd,modinv,Convert +banner() +""" +n1 = 101160013260894210379231391020878154246531211501917641525287013838064105641873685273682200363965750860043980554926996771004697813924018366330613894159009241440066954185337675909482468504824750801346658013253206226485930206600036498618437728843373496089729788328065664820868923399881331844439326306628030735331 +n2 = 10210032872259313686164929473710869592253665432474968016181665104415833992599841926829524498430031021642288824945683044264288937821741278527156550423507713336648261819557381748119064650541556448192793186877429032749223390372405186620392499684387407129200331654256366265932387530132500098451224874600895892420947291972547271991706165603868937708772321221206586800972518013238899316242083977031307714803896630612616326248775444788388309984437812243115218989690016673 +c1 = 66392227979404854586458510145632770314092785183583016343730600866783415262123689751268136986554015242755982639115194608534311988971825645169411730748186710947220673034519486951708550346274786041388143262608730637962604985755406789741345581700390500478433427709495522821473858104289236940045533583368435030007 +c2 = 930631363282343082351877158963544600758567980445720982159124066613164772521801283854718425072511342860751113498013426077785323580215340717638119847338418916957048868138332980175665931485108461262077829550248080371766930777925758187526884947593887945397880426339790518082874861594313920319799945895788141894706108889222173060684161230756671422619830375801046671640406258873119163443168478229210037764301299889548125261094599251838443625348832760001827881979679672 +e = 65537 +""" +n1 = int(input(">>> n1 = ")) +n2 = int(input(">>> n2 = ")) +c1 = int(input(">>> c1 = ")) +c2 = int(input(">>> c2 = ")) +e = int(input(">>> e = ")) + + +if egcd(n1,n2)[0] == 1: + print("[-] Sorry , gcd(n1,n2) = 1") + exit() +else: + 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) + try: + m1 = pow(c1,d1,n1) + Convert(m1) + except TypeError: + pass + try: + m2 = pow(c2,d2,n2) + Convert(m2) + except TypeError: + pass + diff --git a/Attacks/RSA_common_modulus.py b/Attacks/RSA_common_modulus.py new file mode 100644 index 0000000..a0407a7 --- /dev/null +++ b/Attacks/RSA_common_modulus.py @@ -0,0 +1,52 @@ +from banner import * +from utilis import egcd,Convert +banner() +""" +n = 121785996773018308653850214729611957957750585856946607620398279656647965006857599756926384863459274369411103073349913717154710735727786240206066327436155758154142877120260776520601315370480059127244029804523614658953301573686851312721445206131147094674807765817210890772194336025491364961932882951123597124291 +e2 = 343223 +c2 = 99993713982446651581396992055360571139557381122865583938229634474666415937105325664345678113405954865343401854091338680448775405253508255042453184099961570780032181898606546389573694481401653361757628850127420072609555997892925890632116852740542002226555293049123266123721696951805937683483979653786235824108 +e1 = 65537 +c1 = 5050983197907648139720782448847677677343236446273586870502111273113384857588837608900494692102715861436825279596563904392832518247929761994240007673498974877828278590361242528762459283022987952424770766975922016521475963712698089809426428406068793291250622593222599407825968002220906973019105007856539702124 +""" +try: + import gmpy2 + from Crypto.Util.number import GCD + + def neg_pow(a, b, n): + assert b < 0 + assert GCD(a, n) == 1 + res = int(gmpy2.invert(a, n)) + res = pow(res, b*(-1), n) + return res + + def common_modulus(e1, e2, n, c1, c2): + g, a, b = egcd(e1, e2) + if a < 0: + c1 = neg_pow(c1, a, n) + else: + c1 = pow(c1, a, n) + if b < 0: + c2 = neg_pow(c2, b, n) + else: + c2 = pow(c2, b, n) + ct = c1*c2 % n + m = int(gmpy2.iroot(ct, g)[0]) + return m + """ + c1 = int(input(">>> c1 = ")) + c2 = int(input(">>> c2 = ")) + e1 = int(input(">>> e1 = ")) + e2 = int(input(">>> e2 = ")) + n = int(input(">>> n = ")) + """ + Convert(common_modulus(e1, e2, n, c1, c2)) +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] e1, e2, n, c1, c2 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() +except: + slowprint("\n[-] False Attack !") diff --git a/Attacks/RSA_hasted.py b/Attacks/RSA_hasted.py new file mode 100644 index 0000000..640f62c --- /dev/null +++ b/Attacks/RSA_hasted.py @@ -0,0 +1,45 @@ +from banner import * +from utilis import inv_pow,mul_inv,Convert +import functools +banner() + +""" +N1 = 79608037716527910392060670707842954224114341083822168077002144855358998405023007345791355970838437273653492726857398313047195654933011803740498167538754807659255275632647165202835846338059572102420992692073303341392512490988413552501419357400503232190597741120726276250753866130679586474440949586692852365179 +C1 = 34217065803425349356447652842993191079705593197469002356250751196039765990549766822180265723173964726087016890980051189787233837925650902081362222218365748633591895514369317316450142279676583079298758397507023942377316646300547978234729578678310028626408502085957725408232168284955403531891866121828640919987 +N2 = 58002222048141232855465758799795991260844167004589249261667816662245991955274977287082142794911572989261856156040536668553365838145271642812811609687362700843661481653274617983708937827484947856793885821586285570844274545385852401777678956217807768608457322329935290042362221502367207511491516411517438589637 +C2 = 48038542572368143315928949857213341349144690234757944150458420344577988496364306227393161112939226347074838727793761695978722074486902525121712796142366962172291716190060386128524977245133260307337691820789978610313893799675837391244062170879810270336080741790927340336486568319993335039457684586195656124176 +N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 +C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 +""" + + +def chinese_remainder(n, a): + sum = 0 + prod = functools.reduce(lambda a, b: a*b, n) + for n_i, a_i in zip(n, a): + p = prod // n_i + sum += a_i * mul_inv(p, n_i) * p + return sum % prod + +try: + C1 = int(raw_input(">>> c1 = ")) + C2 = int(raw_input(">>> c2 = ")) + C3 = int(raw_input(">>> c3 = ")) + N1 = int(raw_input(">>> n1 = ")) + N2 = int(raw_input(">>> n2 = ")) + N3 = int(raw_input(">>> n3 = ")) + + N = [N1, N2, N3] + C = [C1, C2, C3] + e = len(N) + a = chinese_remainder(N, C) + for n, c in zip(N, C): + assert a % n == c + m = inv_pow(a, e) + Convert(m) +except ValueError: + slowprint("\n[-] c1,c2,c3,n1,n2,n3 Must Be Integar Number") +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() diff --git a/Attacks/RSA_multiPrime1.py b/Attacks/RSA_multiPrime1.py new file mode 100644 index 0000000..88cd411 --- /dev/null +++ b/Attacks/RSA_multiPrime1.py @@ -0,0 +1,37 @@ +from banner import * +from utilis import egcd,modinv,Convert +from Factorizations.ecm import * +banner() + +""" +c= 3821925911648555519353747434606743159593808677487039861592438384426669998207423450606829031692403202928227703884307291926528640413305346863805555214851644456742958636273721157021584443312591620736285469414067076228984358550669307967587995994219000349054979046909041864106400708453105658165917613077273501 +n= 6311257310749529896994764164885908074730315623107218148732436180339784730655096846277587690299624960654670853389184027362495475005388709090759335907428646246751073917955576737663877861242491426053238800688758573959939180213510980211538490409598005851282273664989880554327678869807688158210471903939248513 +e= 65537 +prime = [2160890461,2247289019,2250778319,2442210431,2458778093,2534226749,2535292559,2546035901,2651829007,2690421313,2737511971,2807722121,2985359177,3074912623,3142693039,3144852421,3159476069,3166527541,3269492927,3328687379,3493484429,3505945799,3538145749,3610828651,3699668617,3715792519,4036077043,4058968889,4089517513,4116792439,4262477123,4291039453] +""" + +try: + + c = int(input(">>> c = ")) + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + prime = primefactors(n) + + phi = 1 + for i in prime: + phi *= i-1 + + d = modinv(e, phi) + m = pow(c, d, n) + Convert(m) + +except IndexError: + slowprint("[-] Sorry Can't Factorize n ") +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,n,e Must Be Integar Number") +except KeyboardInterrupt: + exit() +except: + slowprint("[-] False Attack !") diff --git a/Attacks/RSA_wiener.py b/Attacks/RSA_wiener.py new file mode 100644 index 0000000..28aa036 --- /dev/null +++ b/Attacks/RSA_wiener.py @@ -0,0 +1,41 @@ +from banner import * +from utilis import reduites_fraction_continue,fraction_continue,division_euclidienne,Convert +import random +banner() + +""" +#Example : +n = 744818955050534464823866087257532356968231824820271085207879949998948199709147121321290553099733152323288251591199926821010868081248668951049658913424473469563234265317502534369961636698778949885321284313747952124526309774208636874553139856631170172521493735303157992414728027248540362231668996541750186125327789044965306612074232604373780686285181122911537441192943073310204209086616936360770367059427862743272542535703406418700365566693954029683680217414854103 +e = 57595780582988797422250554495450258341283036312290233089677435648298040662780680840440367886540630330262961400339569961467848933132138886193931053170732881768402173651699826215256813839287157821765771634896183026173084615451076310999329120859080878365701402596570941770905755711526708704996817430012923885310126572767854017353205940605301573014555030099067727738540219598443066483590687404131524809345134371422575152698769519371943813733026109708642159828957941 +c = 305357304207903396563769252433798942116307601421155386799392591523875547772911646596463903009990423488430360340024642675941752455429625701977714941340413671092668556558724798890298527900305625979817567613711275466463556061436226589272364057532769439646178423063839292884115912035826709340674104581566501467826782079168130132642114128193813051474106526430253192254354664739229317787919578462780984845602892238745777946945435746719940312122109575086522598667077632 +""" + +try: + n = int(input(">>> n = ")) + e = int(input(">>> e = ")) + + def wiener(n, e): + fc = fraction_continue(e, n) + reduites = reduites_fraction_continue(fc) + message_clair = random.randint(10**1,10**5) + message_chiffre = pow(message_clair, e, n) + l = len(reduites) + i = 0 + while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: + i += 1 + if i != l: + return (reduites[i][1]) + else: + print("[-] Sorry it's Not Wiener Attack\n") + exit(0) + + d = wiener(n,e) + print("\nd = ",d) + c = int(input(">>> c = ")) + decode = pow(c,d,n) + Convert(decode) + +except ImportError: + slowprint("\n[-] Module Not Setup") +except ValueError: + slowprint("\n[-] c,p,q,e Must Be Integar Number") From 26926c4d97b57f3797f9795caa2712f6b6642d95 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:47:10 +0200 Subject: [PATCH 118/122] Delete s --- Attacks/s | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Attacks/s diff --git a/Attacks/s b/Attacks/s deleted file mode 100644 index 8b13789..0000000 --- a/Attacks/s +++ /dev/null @@ -1 +0,0 @@ - From d09778deb12913f7ad6de5801911d9a75b2512ad Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Wed, 6 Nov 2019 18:49:15 +0200 Subject: [PATCH 119/122] Update README.md --- README.md | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8332b9d..3b0ce5b 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,10 @@ **What's X-RSA ?** - it's a Tool Which contains a many of attack types in RSA such as Hasted, Common Modulus, Chinese Remainder Theorem, Wiener ... etc , and it's still under development and adding other Attacks. -**What's New in X-RSA ?** -- Added [ New Attacks , Factorization Methods ] To X-RSA V0.3 And Fixing Many Error in V0.2 - **Why X-RSA ?** - X-RSA help you in [CTF , Penetration Testing , Decryption] -- Written By [ Python 2.7 ] +- Written By [ Python 3 ] # Installing and Running Tool @@ -20,21 +17,12 @@ git clone https://github.com/X-Vector/X-RSA.git 2 - Download Requirement ``` apt install libgmp-dev libmpfr-dev libmpc-dev -pip install -r requirement.txt +pip3 install -r requirement.txt ``` 3 - Run Tool ``` -python Attack.py +python3 Attack.py ``` -# Screenshots -**1 - X-RSA** -![X-RSA](https://2.top4top.net/p_1265rgruu1.png) - -**2 - X-RSA Attackes** -![X-RSA](https://3.top4top.net/p_1276y88c71.png) - -**3 - X-RSA Factorization** -![X-RSA](https://1.top4top.net/p_1276dxpcy1.png) - Coded By X-Vector - [Facebook](https://www.facebook.com/X.Vector1) - [Linkedin](https://www.linkedin.com/in/x-vector/) - [Twitter](https://twitter.com/@XVector11) From f39358f7c39d3042721db711ef447b79044c4355 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelfatah Date: Thu, 28 Nov 2019 10:13:24 +0200 Subject: [PATCH 120/122] Update RSA_hasted.py --- Attacks/RSA_hasted.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Attacks/RSA_hasted.py b/Attacks/RSA_hasted.py index 640f62c..5e4a200 100644 --- a/Attacks/RSA_hasted.py +++ b/Attacks/RSA_hasted.py @@ -22,12 +22,12 @@ def chinese_remainder(n, a): return sum % prod try: - C1 = int(raw_input(">>> c1 = ")) - C2 = int(raw_input(">>> c2 = ")) - C3 = int(raw_input(">>> c3 = ")) - N1 = int(raw_input(">>> n1 = ")) - N2 = int(raw_input(">>> n2 = ")) - N3 = int(raw_input(">>> n3 = ")) + C1 = int(input(">>> c1 = ")) + C2 = int(input(">>> c2 = ")) + C3 = int(input(">>> c3 = ")) + N1 = int(input(">>> n1 = ")) + N2 = int(input(">>> n2 = ")) + N3 = int(input(">>> n3 = ")) N = [N1, N2, N3] C = [C1, C2, C3] From c5ca8bbfd7baaba87c6bc7bb8a4743505cfb432a Mon Sep 17 00:00:00 2001 From: X-Junior Date: Sun, 15 May 2022 00:49:24 +0200 Subject: [PATCH 121/122] Boneh Durfee Attack , Fix other Attacks --- Attack.py | 6 +- Attacks/RSA_boneh_durfee.py | 357 ++++++++++++++++++++++++++++++++++ Attacks/RSA_common_modulus.py | 4 +- Attacks/RSA_hasted.py | 21 +- 4 files changed, 375 insertions(+), 13 deletions(-) create mode 100644 Attacks/RSA_boneh_durfee.py diff --git a/Attack.py b/Attack.py index 73fa8fb..8d9c306 100644 --- a/Attack.py +++ b/Attack.py @@ -24,7 +24,8 @@ [11] - Attack(c,d,n,e)\033[92m [12] - Attack(c,n,e) \033[93m [ Multi Prime Number ] [13] - Attack(c,e = 3)\033[0m -[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Factor ] +[14] - Attack(c1,c2,n1,n2,e) \033[96m [ Common Factor ] +[15] - Attack(c,n,e) \033[95m [ boneh durfee ] [0] - Exit \033[92m """) x = int(input(">>> ")) @@ -70,6 +71,9 @@ elif x == 14: os.system(clear) import Attacks.RSA_common_exponent + elif x == 15: + os.system(clear) + import Attacks.RSA_boneh_durfee else: exit() else: diff --git a/Attacks/RSA_boneh_durfee.py b/Attacks/RSA_boneh_durfee.py new file mode 100644 index 0000000..a9fac02 --- /dev/null +++ b/Attacks/RSA_boneh_durfee.py @@ -0,0 +1,357 @@ + + +from __future__ import print_function +from banner import * +banner() +# This file was *autogenerated* from the file boneh_durfee.sage +from sage.all_cmdline import * # import sage library +from Crypto.Util.number import long_to_bytes +_sage_const_7 = Integer(7); _sage_const_0 = Integer(0); _sage_const_1 = Integer(1); _sage_const_60 = Integer(60); _sage_const_2 = Integer(2); _sage_const_0xc2fd2913bae61f845ac94e4ee1bb10d8531dda830d31bb221dac5f179a8f883f15046d7aa179aff848db2734b8f88cc73d09f35c445c74ee35b01a96eb7b0a6ad9cb9ccd6c02c3f8c55ecabb55501bb2c318a38cac2db69d510e152756054aaed064ac2a454e46d9b3b755b67b46906fbff8dd9aeca6755909333f5f81bf74db = Integer(0xc2fd2913bae61f845ac94e4ee1bb10d8531dda830d31bb221dac5f179a8f883f15046d7aa179aff848db2734b8f88cc73d09f35c445c74ee35b01a96eb7b0a6ad9cb9ccd6c02c3f8c55ecabb55501bb2c318a38cac2db69d510e152756054aaed064ac2a454e46d9b3b755b67b46906fbff8dd9aeca6755909333f5f81bf74db); _sage_const_0x19441f679c9609f2484eb9b2658d7138252b847b2ed8ad182be7976ed57a3e441af14897ce041f3e07916445b88181c22f510150584eee4b0f776a5a487a4472a99f2ddc95efdd2b380ab4480533808b8c92e63ace57fb42bac8315fa487d03bec86d854314bc2ec4f99b192bb98710be151599d60f224114f6b33f47e357517 = Integer(0x19441f679c9609f2484eb9b2658d7138252b847b2ed8ad182be7976ed57a3e441af14897ce041f3e07916445b88181c22f510150584eee4b0f776a5a487a4472a99f2ddc95efdd2b380ab4480533808b8c92e63ace57fb42bac8315fa487d03bec86d854314bc2ec4f99b192bb98710be151599d60f224114f6b33f47e357517); _sage_const_p18 = RealNumber('.18'); _sage_const_4 = Integer(4); _sage_const_0p292 = RealNumber('0.292') + +import time +from sage.all import * +preparser(True) + +############################################ +# Config +########################################## + +""" +Setting debug to true will display more informations +about the lattice, the bounds, the vectors... +""" +debug = True + +""" +Setting strict to true will stop the algorithm (and +return (-1, -1)) if we don't have a correct +upperbound on the determinant. Note that this +doesn't necesseraly mean that no solutions +will be found since the theoretical upperbound is +usualy far away from actual results. That is why +you should probably use `strict = False` +""" +strict = False + +""" +This is experimental, but has provided remarkable results +so far. It tries to reduce the lattice as much as it can +while keeping its efficiency. I see no reason not to use +this option, but if things don't work, you should try +disabling it +""" +helpful_only = True +dimension_min = _sage_const_7 # stop removing if lattice reaches that dimension + +############################################ +# Functions +########################################## + +# display stats on helpful vectors +def helpful_vectors(BB, modulus): + nothelpful = _sage_const_0 + for ii in range(BB.dimensions()[_sage_const_0 ]): + if BB[ii,ii] >= modulus: + nothelpful += _sage_const_1 + + print(nothelpful, "/", BB.dimensions()[_sage_const_0 ], " vectors are not helpful") + +# display matrix picture with 0 and X +def matrix_overview(BB, bound): + for ii in range(BB.dimensions()[_sage_const_0 ]): + a = ('%02d ' % ii) + for jj in range(BB.dimensions()[_sage_const_1 ]): + a += '0' if BB[ii,jj] == _sage_const_0 else 'X' + if BB.dimensions()[_sage_const_0 ] < _sage_const_60 : + a += ' ' + if BB[ii, ii] >= bound: + a += '~' + print(a) + +# tries to remove unhelpful vectors +# we start at current = n-1 (last vector) +def remove_unhelpful(BB, monomials, bound, current): + # end of our recursive function + if current == -_sage_const_1 or BB.dimensions()[_sage_const_0 ] <= dimension_min: + return BB + + # we start by checking from the end + for ii in range(current, -_sage_const_1 , -_sage_const_1 ): + # if it is unhelpful: + if BB[ii, ii] >= bound: + affected_vectors = _sage_const_0 + affected_vector_index = _sage_const_0 + # let's check if it affects other vectors + for jj in range(ii + _sage_const_1 , BB.dimensions()[_sage_const_0 ]): + # if another vector is affected: + # we increase the count + if BB[jj, ii] != _sage_const_0 : + affected_vectors += _sage_const_1 + affected_vector_index = jj + + # level:0 + # if no other vectors end up affected + # we remove it + if affected_vectors == _sage_const_0 : + print("* removing unhelpful vector", ii) + BB = BB.delete_columns([ii]) + BB = BB.delete_rows([ii]) + monomials.pop(ii) + BB = remove_unhelpful(BB, monomials, bound, ii-_sage_const_1 ) + return BB + + # level:1 + # if just one was affected we check + # if it is affecting someone else + elif affected_vectors == _sage_const_1 : + affected_deeper = True + for kk in range(affected_vector_index + _sage_const_1 , BB.dimensions()[_sage_const_0 ]): + # if it is affecting even one vector + # we give up on this one + if BB[kk, affected_vector_index] != _sage_const_0 : + affected_deeper = False + # remove both it if no other vector was affected and + # this helpful vector is not helpful enough + # compared to our unhelpful one + if affected_deeper and abs(bound - BB[affected_vector_index, affected_vector_index]) < abs(bound - BB[ii, ii]): + print("* removing unhelpful vectors", ii, "and", affected_vector_index) + BB = BB.delete_columns([affected_vector_index, ii]) + BB = BB.delete_rows([affected_vector_index, ii]) + monomials.pop(affected_vector_index) + monomials.pop(ii) + BB = remove_unhelpful(BB, monomials, bound, ii-_sage_const_1 ) + return BB + # nothing happened + return BB + +""" +Returns: +* 0,0 if it fails +* -1,-1 if `strict=true`, and determinant doesn't bound +* x0,y0 the solutions of `pol` +""" +def boneh_durfee(pol, modulus, mm, tt, XX, YY): + """ + Boneh and Durfee revisited by Herrmann and May + + finds a solution if: + * d < N^delta + * |x| < e^delta + * |y| < e^0.5 + whenever delta < 1 - sqrt(2)/2 ~ 0.292 + """ + + # substitution (Herrman and May) + PR = PolynomialRing(ZZ, names=('u', 'x', 'y',)); (u, x, y,) = PR._first_ngens(3) + Q = PR.quotient(x*y + _sage_const_1 - u) # u = xy + 1 + polZ = Q(pol).lift() + + UU = XX*YY + _sage_const_1 + + # x-shifts + gg = [] + for kk in range(mm + _sage_const_1 ): + for ii in range(mm - kk + _sage_const_1 ): + xshift = x**ii * modulus**(mm - kk) * polZ(u, x, y)**kk + gg.append(xshift) + gg.sort() + + # x-shifts list of monomials + monomials = [] + for polynomial in gg: + for monomial in polynomial.monomials(): + if monomial not in monomials: + monomials.append(monomial) + monomials.sort() + + # y-shifts (selected by Herrman and May) + for jj in range(_sage_const_1 , tt + _sage_const_1 ): + for kk in range(floor(mm/tt) * jj, mm + _sage_const_1 ): + yshift = y**jj * polZ(u, x, y)**kk * modulus**(mm - kk) + yshift = Q(yshift).lift() + gg.append(yshift) # substitution + + # y-shifts list of monomials + for jj in range(_sage_const_1 , tt + _sage_const_1 ): + for kk in range(floor(mm/tt) * jj, mm + _sage_const_1 ): + monomials.append(u**kk * y**jj) + + # construct lattice B + nn = len(monomials) + BB = Matrix(ZZ, nn) + for ii in range(nn): + BB[ii, _sage_const_0 ] = gg[ii](_sage_const_0 , _sage_const_0 , _sage_const_0 ) + for jj in range(_sage_const_1 , ii + _sage_const_1 ): + if monomials[jj] in gg[ii].monomials(): + BB[ii, jj] = gg[ii].monomial_coefficient(monomials[jj]) * monomials[jj](UU,XX,YY) + + # Prototype to reduce the lattice + if helpful_only: + # automatically remove + BB = remove_unhelpful(BB, monomials, modulus**mm, nn-_sage_const_1 ) + # reset dimension + nn = BB.dimensions()[_sage_const_0 ] + if nn == _sage_const_0 : + print("failure") + return _sage_const_0 ,_sage_const_0 + + # check if vectors are helpful + if debug: + helpful_vectors(BB, modulus**mm) + + # check if determinant is correctly bounded + det = BB.det() + bound = modulus**(mm*nn) + if det >= bound: + print("We do not have det < bound. Solutions might not be found.") + print("Try with highers m and t.") + if debug: + diff = (log(det) - log(bound)) / log(_sage_const_2 ) + print("size det(L) - size e^(m*n) = ", floor(diff)) + if strict: + return -_sage_const_1 , -_sage_const_1 + else: + print("det(L) < e^(m*n) (good! If a solution exists < N^delta, it will be found)") + + # display the lattice basis + #if debug: + #matrix_overview(BB, modulus**mm) + + # LLL + if debug: + print("optimizing basis of the lattice via LLL, this can take a long time") + + BB = BB.LLL() + + if debug: + print("LLL is done!") + + # transform vector i & j -> polynomials 1 & 2 + if debug: + print("looking for independent vectors in the lattice") + found_polynomials = False + + for pol1_idx in range(nn - _sage_const_1 ): + for pol2_idx in range(pol1_idx + _sage_const_1 , nn): + # for i and j, create the two polynomials + PR = PolynomialRing(ZZ, names=('w', 'z',)); (w, z,) = PR._first_ngens(2) + pol1 = pol2 = _sage_const_0 + for jj in range(nn): + pol1 += monomials[jj](w*z+_sage_const_1 ,w,z) * BB[pol1_idx, jj] / monomials[jj](UU,XX,YY) + pol2 += monomials[jj](w*z+_sage_const_1 ,w,z) * BB[pol2_idx, jj] / monomials[jj](UU,XX,YY) + + # resultant + PR = PolynomialRing(ZZ, names=('q',)); (q,) = PR._first_ngens(1) + rr = pol1.resultant(pol2) + + # are these good polynomials? + if rr.is_zero() or rr.monomials() == [_sage_const_1 ]: + continue + else: + print("found them, using vectors", pol1_idx, "and", pol2_idx) + found_polynomials = True + break + if found_polynomials: + break + + if not found_polynomials: + print("no independant vectors could be found. This should very rarely happen...") + return _sage_const_0 , _sage_const_0 + + rr = rr(q, q) + + # solutions + soly = rr.roots() + + if len(soly) == _sage_const_0 : + print("Your prediction (delta) is too small") + return _sage_const_0 , _sage_const_0 + + soly = soly[_sage_const_0 ][_sage_const_0 ] + ss = pol1(q, soly) + solx = ss.roots()[_sage_const_0 ][_sage_const_0 ] + + # + return solx, soly + + + +try: + ############################################ + # How To Use This Script + ########################################## + + # + # The problem to solve (edit the following values) + # + + # the modulus + + N = int(input(">>> n = ")) + e = int(input(">>> e = ")) + c = int(input(">>> c = ")) + + # the hypothesis on the private exponent (the theoretical maximum is 0.292) + delta = _sage_const_p18 # this means that d < N^delta + + # + # Lattice (tweak those values) + # + + # you should tweak this (after a first run), (e.g. increment it until a solution is found) + m = _sage_const_4 # size of the lattice (bigger the better/slower) + + # you need to be a lattice master to tweak these + t = int((_sage_const_1 -_sage_const_2 *delta) * m) # optimization from Herrmann and May + X = _sage_const_2 *floor(N**delta) # this _might_ be too much + Y = floor(N**(_sage_const_1 /_sage_const_2 )) # correct if p, q are ~ same size + + # + # Don't touch anything below + # + + # Problem put in equation + P = PolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = P._first_ngens(2) + A = int((N+_sage_const_1 )/_sage_const_2 ) + pol = _sage_const_1 + x * (A + y) + + # + # Find the solutions! + # + + # Checking bounds + #if debug: + #print("=== checking values ===") + #print("* delta:", delta) + #print("* delta < 0.292", delta < _sage_const_0p292 ) + #print("* size of e:", int(log(e)/log(_sage_const_2 ))) + #print("* size of N:", int(log(N)/log(_sage_const_2 ))) + #print("* m:", m, ", t:", t) + + # boneh_durfee + if debug: + print("=== running algorithm ===") + start_time = time.time() + + solx, soly = boneh_durfee(pol, e, m, t, X, Y) + + # found a solution? + if solx > _sage_const_0 : + print("=== solution found ===") + if False: + print("x:", solx) + print("y:", soly) + + d = int(pol(solx, soly) / e) + print( "private key found:", d) + print(long_to_bytes(pow(c,d,N)).decode()) + else: + print("=== no solution was found ===") + +except AssertionError: + slowprint("\n[-] Wrong Data") +except KeyboardInterrupt: + exit() + + + diff --git a/Attacks/RSA_common_modulus.py b/Attacks/RSA_common_modulus.py index a0407a7..52a8fea 100644 --- a/Attacks/RSA_common_modulus.py +++ b/Attacks/RSA_common_modulus.py @@ -32,13 +32,13 @@ def common_modulus(e1, e2, n, c1, c2): ct = c1*c2 % n m = int(gmpy2.iroot(ct, g)[0]) return m - """ + c1 = int(input(">>> c1 = ")) c2 = int(input(">>> c2 = ")) e1 = int(input(">>> e1 = ")) e2 = int(input(">>> e2 = ")) n = int(input(">>> n = ")) - """ + Convert(common_modulus(e1, e2, n, c1, c2)) except ImportError: slowprint("\n[-] Module Not Setup") diff --git a/Attacks/RSA_hasted.py b/Attacks/RSA_hasted.py index 5e4a200..92661a4 100644 --- a/Attacks/RSA_hasted.py +++ b/Attacks/RSA_hasted.py @@ -1,5 +1,6 @@ from banner import * from utilis import inv_pow,mul_inv,Convert + import functools banner() @@ -11,7 +12,8 @@ N3 = 95136786745520478217269528603148282473715660891325372806774750455600642337159386952455144391867750492077191823630711097423473530235172124790951314315271310542765846789908387211336846556241994561268538528319743374290789112373774893547676601690882211706889553455962720218486395519200617695951617114702861810811 C3 = 55139001168534905791033093049281485849516290567638780139733282880064346293967470884523842813679361232423330290836063248352131025995684341143337417237119663347561882637003640064860966432102780676449991773140407055863369179692136108534952624411669691799286623699981636439331427079183234388844722074263884842748 """ - +N = [] +C = [] def chinese_remainder(n, a): sum = 0 @@ -22,15 +24,14 @@ def chinese_remainder(n, a): return sum % prod try: - C1 = int(input(">>> c1 = ")) - C2 = int(input(">>> c2 = ")) - C3 = int(input(">>> c3 = ")) - N1 = int(input(">>> n1 = ")) - N2 = int(input(">>> n2 = ")) - N3 = int(input(">>> n3 = ")) - - N = [N1, N2, N3] - C = [C1, C2, C3] + num = int(input(">>> number of n,c pairs = ")) + N = [] + C = [] + for i in range(num): + n = int(input(">>> n = ")) + c = int(input(">>> c = ")) + N.append(n) + C.append(c) e = len(N) a = chinese_remainder(N, C) for n, c in zip(N, C): From 291d4c74a528d3c5c5e55207cdc4ceda001142bc Mon Sep 17 00:00:00 2001 From: "sourcery-ai[bot]" <58596630+sourcery-ai[bot]@users.noreply.github.com> Date: Sun, 4 Jun 2023 22:24:51 +0300 Subject: [PATCH 122/122] 'Refactored by Sourcery' (#7) Co-authored-by: Sourcery AI <> --- Attacks/RSA5.py | 3 +- Attacks/RSA_boneh_durfee.py | 90 ++++++++++++++--------------------- Attacks/RSA_common_modulus.py | 20 +++----- Attacks/RSA_hasted.py | 10 ++-- Attacks/RSA_wiener.py | 21 ++++---- Factorizations/ecm.py | 8 ++-- Factorizations/factordb.py | 12 ++--- Factorizations/fermat.py | 4 +- Factorizations/qs.py | 32 +++++-------- banner.py | 20 +++----- utilis.py | 4 +- 11 files changed, 84 insertions(+), 140 deletions(-) diff --git a/Attacks/RSA5.py b/Attacks/RSA5.py index 03c89e2..a874d69 100644 --- a/Attacks/RSA5.py +++ b/Attacks/RSA5.py @@ -16,8 +16,7 @@ def premRSA(n,e,d,c): assert bitLenD0 >= bitLenN/2 d = halfdPartialKeyRecoveryAttack(d,2048,4096,n,e) - m = pow(c,d,n) - return m + return pow(c,d,n) def halfdPartialKeyRecoveryAttack(d0,d0BitSize,nBitSize,n="n",e="e"): test = pow(3, e, n) diff --git a/Attacks/RSA_boneh_durfee.py b/Attacks/RSA_boneh_durfee.py index a9fac02..f40ca93 100644 --- a/Attacks/RSA_boneh_durfee.py +++ b/Attacks/RSA_boneh_durfee.py @@ -79,8 +79,8 @@ def remove_unhelpful(BB, monomials, bound, current): for ii in range(current, -_sage_const_1 , -_sage_const_1 ): # if it is unhelpful: if BB[ii, ii] >= bound: - affected_vectors = _sage_const_0 - affected_vector_index = _sage_const_0 + affected_vectors = _sage_const_0 + affected_vector_index = _sage_const_0 # let's check if it affects other vectors for jj in range(ii + _sage_const_1 , BB.dimensions()[_sage_const_0 ]): # if another vector is affected: @@ -92,7 +92,7 @@ def remove_unhelpful(BB, monomials, bound, current): # level:0 # if no other vectors end up affected # we remove it - if affected_vectors == _sage_const_0 : + if affected_vectors == _sage_const_0: print("* removing unhelpful vector", ii) BB = BB.delete_columns([ii]) BB = BB.delete_rows([ii]) @@ -100,16 +100,14 @@ def remove_unhelpful(BB, monomials, bound, current): BB = remove_unhelpful(BB, monomials, bound, ii-_sage_const_1 ) return BB - # level:1 - # if just one was affected we check - # if it is affecting someone else - elif affected_vectors == _sage_const_1 : - affected_deeper = True - for kk in range(affected_vector_index + _sage_const_1 , BB.dimensions()[_sage_const_0 ]): - # if it is affecting even one vector - # we give up on this one - if BB[kk, affected_vector_index] != _sage_const_0 : - affected_deeper = False + elif affected_vectors == _sage_const_1: + affected_deeper = all( + BB[kk, affected_vector_index] == _sage_const_0 + for kk in range( + affected_vector_index + _sage_const_1, + BB.dimensions()[_sage_const_0], + ) + ) # remove both it if no other vector was affected and # this helpful vector is not helpful enough # compared to our unhelpful one @@ -142,7 +140,8 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): """ # substitution (Herrman and May) - PR = PolynomialRing(ZZ, names=('u', 'x', 'y',)); (u, x, y,) = PR._first_ngens(3) + PR = PolynomialRing(ZZ, names=('u', 'x', 'y',)) + (u, x, y,) = PR._first_ngens(3) Q = PR.quotient(x*y + _sage_const_1 - u) # u = xy + 1 polZ = Q(pol).lift() @@ -163,19 +162,20 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): if monomial not in monomials: monomials.append(monomial) monomials.sort() - + # y-shifts (selected by Herrman and May) for jj in range(_sage_const_1 , tt + _sage_const_1 ): for kk in range(floor(mm/tt) * jj, mm + _sage_const_1 ): yshift = y**jj * polZ(u, x, y)**kk * modulus**(mm - kk) yshift = Q(yshift).lift() gg.append(yshift) # substitution - + # y-shifts list of monomials for jj in range(_sage_const_1 , tt + _sage_const_1 ): - for kk in range(floor(mm/tt) * jj, mm + _sage_const_1 ): - monomials.append(u**kk * y**jj) - + monomials.extend( + u**kk * y**jj + for kk in range(floor(mm / tt) * jj, mm + _sage_const_1) + ) # construct lattice B nn = len(monomials) BB = Matrix(ZZ, nn) @@ -198,7 +198,7 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): # check if vectors are helpful if debug: helpful_vectors(BB, modulus**mm) - + # check if determinant is correctly bounded det = BB.det() bound = modulus**(mm*nn) @@ -213,10 +213,6 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): else: print("det(L) < e^(m*n) (good! If a solution exists < N^delta, it will be found)") - # display the lattice basis - #if debug: - #matrix_overview(BB, modulus**mm) - # LLL if debug: print("optimizing basis of the lattice via LLL, this can take a long time") @@ -230,34 +226,34 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): if debug: print("looking for independent vectors in the lattice") found_polynomials = False - + for pol1_idx in range(nn - _sage_const_1 ): for pol2_idx in range(pol1_idx + _sage_const_1 , nn): # for i and j, create the two polynomials - PR = PolynomialRing(ZZ, names=('w', 'z',)); (w, z,) = PR._first_ngens(2) - pol1 = pol2 = _sage_const_0 + PR = PolynomialRing(ZZ, names=('w', 'z',)) + (w, z,) = PR._first_ngens(2) + pol1 = pol2 = _sage_const_0 for jj in range(nn): pol1 += monomials[jj](w*z+_sage_const_1 ,w,z) * BB[pol1_idx, jj] / monomials[jj](UU,XX,YY) pol2 += monomials[jj](w*z+_sage_const_1 ,w,z) * BB[pol2_idx, jj] / monomials[jj](UU,XX,YY) # resultant - PR = PolynomialRing(ZZ, names=('q',)); (q,) = PR._first_ngens(1) + PR = PolynomialRing(ZZ, names=('q',)) + (q,) = PR._first_ngens(1) rr = pol1.resultant(pol2) - # are these good polynomials? if rr.is_zero() or rr.monomials() == [_sage_const_1 ]: continue - else: - print("found them, using vectors", pol1_idx, "and", pol2_idx) - found_polynomials = True - break + print("found them, using vectors", pol1_idx, "and", pol2_idx) + found_polynomials = True + break if found_polynomials: break if not found_polynomials: print("no independant vectors could be found. This should very rarely happen...") return _sage_const_0 , _sage_const_0 - + rr = rr(q, q) # solutions @@ -290,7 +286,7 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): N = int(input(">>> n = ")) e = int(input(">>> e = ")) c = int(input(">>> c = ")) - + # the hypothesis on the private exponent (the theoretical maximum is 0.292) delta = _sage_const_p18 # this means that d < N^delta @@ -311,23 +307,11 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): # # Problem put in equation - P = PolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = P._first_ngens(2) + P = PolynomialRing(ZZ, names=('x', 'y',)) + (x, y,) = P._first_ngens(2) A = int((N+_sage_const_1 )/_sage_const_2 ) pol = _sage_const_1 + x * (A + y) - # - # Find the solutions! - # - - # Checking bounds - #if debug: - #print("=== checking values ===") - #print("* delta:", delta) - #print("* delta < 0.292", delta < _sage_const_0p292 ) - #print("* size of e:", int(log(e)/log(_sage_const_2 ))) - #print("* size of N:", int(log(N)/log(_sage_const_2 ))) - #print("* m:", m, ", t:", t) - # boneh_durfee if debug: print("=== running algorithm ===") @@ -336,18 +320,14 @@ def boneh_durfee(pol, modulus, mm, tt, XX, YY): solx, soly = boneh_durfee(pol, e, m, t, X, Y) # found a solution? - if solx > _sage_const_0 : + if solx > _sage_const_0: print("=== solution found ===") - if False: - print("x:", solx) - print("y:", soly) - d = int(pol(solx, soly) / e) print( "private key found:", d) print(long_to_bytes(pow(c,d,N)).decode()) else: print("=== no solution was found ===") - + except AssertionError: slowprint("\n[-] Wrong Data") except KeyboardInterrupt: diff --git a/Attacks/RSA_common_modulus.py b/Attacks/RSA_common_modulus.py index 52a8fea..53eae8a 100644 --- a/Attacks/RSA_common_modulus.py +++ b/Attacks/RSA_common_modulus.py @@ -16,22 +16,14 @@ def neg_pow(a, b, n): assert b < 0 assert GCD(a, n) == 1 res = int(gmpy2.invert(a, n)) - res = pow(res, b*(-1), n) - return res + return pow(res, b*(-1), n) def common_modulus(e1, e2, n, c1, c2): - g, a, b = egcd(e1, e2) - if a < 0: - c1 = neg_pow(c1, a, n) - else: - c1 = pow(c1, a, n) - if b < 0: - c2 = neg_pow(c2, b, n) - else: - c2 = pow(c2, b, n) - ct = c1*c2 % n - m = int(gmpy2.iroot(ct, g)[0]) - return m + g, a, b = egcd(e1, e2) + c1 = neg_pow(c1, a, n) if a < 0 else pow(c1, a, n) + c2 = neg_pow(c2, b, n) if b < 0 else pow(c2, b, n) + ct = c1*c2 % n + return int(gmpy2.iroot(ct, g)[0]) c1 = int(input(">>> c1 = ")) c2 = int(input(">>> c2 = ")) diff --git a/Attacks/RSA_hasted.py b/Attacks/RSA_hasted.py index 92661a4..52c9224 100644 --- a/Attacks/RSA_hasted.py +++ b/Attacks/RSA_hasted.py @@ -27,11 +27,11 @@ def chinese_remainder(n, a): num = int(input(">>> number of n,c pairs = ")) N = [] C = [] - for i in range(num): - n = int(input(">>> n = ")) - c = int(input(">>> c = ")) - N.append(n) - C.append(c) + for _ in range(num): + n = int(input(">>> n = ")) + c = int(input(">>> c = ")) + N.append(n) + C.append(c) e = len(N) a = chinese_remainder(N, C) for n, c in zip(N, C): diff --git a/Attacks/RSA_wiener.py b/Attacks/RSA_wiener.py index 28aa036..c56163f 100644 --- a/Attacks/RSA_wiener.py +++ b/Attacks/RSA_wiener.py @@ -15,17 +15,16 @@ e = int(input(">>> e = ")) def wiener(n, e): - fc = fraction_continue(e, n) - reduites = reduites_fraction_continue(fc) - message_clair = random.randint(10**1,10**5) - message_chiffre = pow(message_clair, e, n) - l = len(reduites) - i = 0 - while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: - i += 1 - if i != l: - return (reduites[i][1]) - else: + fc = fraction_continue(e, n) + reduites = reduites_fraction_continue(fc) + message_clair = random.randint(10**1,10**5) + message_chiffre = pow(message_clair, e, n) + l = len(reduites) + i = 0 + while i < l and pow(message_chiffre, reduites[i][1], n) != message_clair: + i += 1 + if i != l: + return (reduites[i][1]) print("[-] Sorry it's Not Wiener Attack\n") exit(0) diff --git a/Factorizations/ecm.py b/Factorizations/ecm.py index 79d6ef8..f0b308b 100644 --- a/Factorizations/ecm.py +++ b/Factorizations/ecm.py @@ -34,11 +34,11 @@ def isprime(n, precision=7): d //= 2 s += 1 - for repeat in range(precision): + for _ in range(precision): a = random.randrange(2, n - 2) x = pow(a, d, n) - if x == 1 or x == n - 1: continue + if x in [1, n - 1]: continue for r in range(s - 1): x = pow(x, 2, n) @@ -57,13 +57,13 @@ def pollard_brent(n): g, r, q = 1, 1, 1 while g == 1: x = y - for i in range(r): + for _ in range(r): y = (pow(y, 2, n) + c) % n k = 0 while k < r and g==1: ys = y - for i in range(min(m, r-k)): + for _ in range(min(m, r-k)): y = (pow(y, 2, n) + c) % n q = q * abs(x-y) % n g = gcd(q, n) diff --git a/Factorizations/factordb.py b/Factorizations/factordb.py index affef52..9ca572f 100644 --- a/Factorizations/factordb.py +++ b/Factorizations/factordb.py @@ -18,19 +18,13 @@ def connect(self, reconnect=False): return self.result def get_id(self): - if self.result: - return self.result.json().get("id") - return None + return self.result.json().get("id") if self.result else None def get_status(self): - if self.result: - return self.result.json().get("status") - return None + return self.result.json().get("status") if self.result else None def get_factor_from_api(self): - if self.result: - return self.result.json().get("factors") - return None + return self.result.json().get("factors") if self.result else None def get_factor_list(self): """ diff --git a/Factorizations/fermat.py b/Factorizations/fermat.py index cf93ea9..79f3db2 100644 --- a/Factorizations/fermat.py +++ b/Factorizations/fermat.py @@ -13,7 +13,7 @@ def fermat(n): exit() p = a+b q = a-b - print("%sp =%s"%(Y,G),p) - print("%sq =%s"%(Y,G),q) + print(f"{Y}p ={G}", p) + print(f"{Y}q ={G}", q) diff --git a/Factorizations/qs.py b/Factorizations/qs.py index 2127ab2..e2b8769 100644 --- a/Factorizations/qs.py +++ b/Factorizations/qs.py @@ -170,7 +170,7 @@ def primality_test_miller_rabin(a, iterations): b = random.randint(2, a - 1) j = 0 z = pow_mod(b, m, a) - while not ((j == 0 and z == 1) or z == a - 1): + while (j != 0 or z != 1) and z != a - 1: if (j > 0 and z == 1 or j + 1 == lb): return False j += 1 @@ -376,9 +376,7 @@ def add_column_opt(M_opt, tgt, src): def find_pivot_column_opt(M_opt, j): - if M_opt[j] == 0: - return None - return lowest_set_bit(M_opt[j]) + return None if M_opt[j] == 0 else lowest_set_bit(M_opt[j]) def siqs_solve_matrix_opt(M_opt, n, m): @@ -456,7 +454,7 @@ def siqs_find_factors(n, perfect_squares, smooth_relations): prime_factors = set() for square_indices in perfect_squares: fact = siqs_factor_from_square(n, square_indices, smooth_relations) - if fact != 1 and fact != rem: + if fact not in [1, rem]: if is_probable_prime(fact): if fact not in prime_factors: prime_factors.add(fact) @@ -471,9 +469,8 @@ def siqs_find_factors(n, perfect_squares, smooth_relations): factors.append(rem) rem = 1 break - else: - if fact not in non_prime_factors: - non_prime_factors.add(fact) + elif fact not in non_prime_factors: + non_prime_factors.add(fact) if rem != 1 and non_prime_factors: non_prime_factors.add(rem) @@ -496,7 +493,7 @@ def siqs_find_more_factors_gcd(numbers): for m in numbers: if n != m: fact = gcd(n, m) - if fact != 1 and fact != n and fact != m: + if fact not in [1, n, m]: if fact not in res: res.add(fact) res.add(n // fact) @@ -534,9 +531,7 @@ def siqs_choose_nf_m(d): return 30000, 65536 * 3 if d <= 88: return 50000, 65536 * 3 - if d <= 94: - return 60000, 65536 * 9 - return 100000, 65536 * 9 + return (60000, 65536 * 9) if d <= 94 else (100000, 65536 * 9) def siqs_factorise(n): @@ -602,7 +597,7 @@ def check_factor(n, i, factors): def trial_div_init_primes(n, upper_bound): global small_primes is_prime = [True] * (upper_bound + 1) - is_prime[0:2] = [False] * 2 + is_prime[:2] = [False] * 2 factors = [] small_primes = [] max_i = sqrt_int(upper_bound) @@ -707,8 +702,7 @@ def check_perfect_power(n): def find_prime_factors(n): - perfect_power = check_perfect_power(n) - if perfect_power: + if perfect_power := check_perfect_power(n): factors = [perfect_power[0]] else: digits = len(str(n)) @@ -719,9 +713,7 @@ def find_prime_factors(n): prime_factors = [] for f in set(factors): - for pf in find_all_prime_factors(f): - prime_factors.append(pf) - + prime_factors.extend(iter(find_all_prime_factors(f))) return prime_factors @@ -766,9 +758,7 @@ def factorise(n): factors, rem = trial_div_init_primes(n, 1000000) - if factors: - pass - else: + if not factors: if rem != 1: digits = len(str(rem)) if digits > MAX_DIGITS_POLLARD: diff --git a/banner.py b/banner.py index f9cb3a8..3468f20 100644 --- a/banner.py +++ b/banner.py @@ -19,14 +19,14 @@ def slowprint(s): os.system(clear) is_windows = sys.platform.startswith('win') +# Windows deserves coloring too :D +G = '\033[92m' # green +Y = '\033[93m' # yellow +B = '\033[94m' # blue +R = '\033[91m' # red +W = '\033[0m' # white # Console Colors if is_windows: - # Windows deserves coloring too :D - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white try: import win_unicode_console , colorama win_unicode_console.enable() @@ -37,14 +37,6 @@ def slowprint(s): G = Y = B = R = W = G = Y = B = R = W = '' -else: - G = '\033[92m' # green - Y = '\033[93m' # yellow - B = '\033[94m' # blue - R = '\033[91m' # red - W = '\033[0m' # white - - def banner(): print("""%s _____ ________________ _____ _____ diff --git a/utilis.py b/utilis.py index 5bbb941..878715d 100644 --- a/utilis.py +++ b/utilis.py @@ -68,8 +68,7 @@ def reduites_fraction_continue(a): h1 = 0 k0 = 0 k1 = 1 - count = 0 - while count < l: + for count in range(l): h = a[count] * h1 + h0 h0 = h1 h1 = h @@ -77,7 +76,6 @@ def reduites_fraction_continue(a): k0 = k1 k1 = k reduites.append((k,h)) - count += 1 return (reduites) def floorSqrt(n):