""" RSA_Cracker: Cracks RSA key set by using various attacks """

from RSAExploits.exploits.common_modulus import Common_Modulus
from RSAExploits.exploits.wiener import Wiener
from RSAExploits.exploits.boneh_durfee import Boneh_Durfee
from RSAExploits.exploits.hastad import Hastad
from RSAExploits.exploits.fermat import Fermat
from RSAExploits.exploits.common_factor import Common_Factor
from RSAExploits.exploits.franklin_reiter import Franklin_Reiter

__Exploit_Classes__ = []

def init():
    """ Populate the Exploit_Classes list with exploits to run """
    global __Exploit_Classes__

    __Exploit_Classes__ = []
    __Exploit_Classes__.append(Franklin_Reiter())
    __Exploit_Classes__.append(Common_Modulus())
    __Exploit_Classes__.append(Common_Factor())
    __Exploit_Classes__.append(Wiener())
    __Exploit_Classes__.append(Boneh_Durfee())
    __Exploit_Classes__.append(Hastad())
    __Exploit_Classes__.append(Fermat())

def attack(rsadata_list, info_dict = None, break_on_success = True):
    """ Run all of the exploits in the list on the provided rsadata objects

        Args:
            rsadata_list: A list of RSA_Data objects to exploit
            info_dict: Dictionary providing extra info to certain exploits
            break_on_success: Stop after first successful exploit if true
    """
    
    success = False
    for exploit in __Exploit_Classes__:
        if exploit.run(rsadata_list, info_dict):
            success = True
        if success and break_on_success:
            return success

