def __init__(self, name='Stick', description='', damage=10, weapon_type='', cost=0, condition='sturdy', attacks=[Attack(), Attack(), Attack()]): self.name = name # a weapon's name consists of it's condition and regular name, e.g. 'Sturdy Sword' self.description = description self.condition = condition # condition effects the weapon's damage and other attributes, condition is defaulted to sturdy self.default_damage = damage self.damage = int( self.default_damage * condition_dictionary[self.condition]['damage_multiplier']) # damage changes depending on condition, but it is defaulted at the default damage # weapon's default damage is set by the parameter damage self.weapon_type = weapon_type self.cost = cost # how much it costs to purchase the weapon self.attacks = attacks # list of attacks that the weapon can perform self.critical_chance = condition_dictionary[ self.condition]['critical_chance'] self.critical_multiplier = condition_dictionary[ self.condition]['critical_multiplier']
def unpack_attacks_into_objects(buff_output_dictionary): """unpacks attack attributes into objects within a dictionary""" attack_output_dictionary = {} for attack_group_key in attack_attribute_dictionary: attack_list = [] for attack_attributes in attack_attribute_dictionary[attack_group_key]: if attack_attributes['buff'] in buff_object_dictionary: attack_buff = buff_output_dictionary[attack_attributes['buff']] else: attack_buff = "" attack_list.append( Attack(attack_attributes['name'], attack_attributes['multiplier'], attack_attributes['variance'], attack_buff)) attack_output_dictionary[attack_group_key] = attack_list return attack_output_dictionary
def __init__(self, args, model, dataloarder): self.args = args # Basic # self.cuda = (args.cuda and torch.cuda.is_available()) # setting device if args.cuda and torch.cuda.is_available(): """ if argument is given and cuda is available """ self.device = torch.device('cuda') else: self.device = torch.device('cpu') self.epoch = args.epoch self.batch_size = args.batch_size self.eps = args.eps self.lr = args.lr self.y_dim = args.y_dim self.target = args.target self.dataset = args.dataset self.data_loader = dataloarder # dict self.global_epoch = 0 self.global_iter = 0 self.print_ = not args.silent self.net = model #need the model to be initialized here self.env_name = args.env_name self.tensorboard = args.tensorboard self.visdom = args.visdom self.ckpt_dir = Path(args.ckpt_dir).joinpath(args.env_name) if not self.ckpt_dir.exists(): self.ckpt_dir.mkdir(parents=True, exist_ok=True) self.output_dir = Path(args.output_dir).joinpath(args.env_name) if not self.output_dir.exists(): self.output_dir.mkdir(parents=True, exist_ok=True) # Visualization Tools self.visualization_init(args) # Histories self.history = dict() self.history['acc'] = 0. self.history['epoch'] = 0 self.history['iter'] = 0 # Models & Optimizers # self.model_init(args) self.load_ckpt = args.load_ckpt if self.load_ckpt != '': self.load_checkpoint(self.load_ckpt) # Adversarial Perturbation Generator #criterion = cuda(torch.nn.CrossEntropyLoss(), self.cuda) criterion = F.cross_entropy self.attack = Attack(self.net, criterion=criterion)
def askUser(): print("==========================================") print("\n Please select an attack type:") print("\n 1. UDP Flood") print("\n 2. Ping of death") print("\n=========================================") try: valid = [1,2] answer = int(input("Choice [1-2]: ")) if answer not in valid: print("Please enter a valid number.") askUser() else: if answer == 1: host = input('Host: ') port = int(input('Post: ')) att = Attack('udpflood', host, port) isUp = att.checkTargetAlive() print(isUp) if isUp: att.attack() else: print("Could not check if target is up.") keepGoing = input("Do you still want to attack target? (y/n)") if keepGoing == 'y' or keepGoing == 'Y': att.attack() elif answer == 'n' or answer == 'N': askUser() else: pass else: pass finally: print("Done.")
def choose(arg): attack = str(accueil(arg)) if attack == "1": print("\n\t\t\t ***** Wiener Attack *****") args = input( "\n\t\t[*] Arguments ([-h] -n modulus -e exponent):\n\n\t\t\t" ).split() parser = argparse.ArgumentParser( description='This program allows to carry out a Wiener Attack') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-e', dest='e', type=int, help='RSA public key exponent', required=True) params = parser.parse_args(args) attack_object = Attack(params) attack_object.wiener() elif attack == "2": print("\n\t\t\t ***** Hastad Attack *****") try: args = input( "\n\t\t[*] Arguments ([-h] -n0 modulus_key0 -n1 modulus_key1 -n2 modulus_key2 -e public_exponent -c0 cipher1 -c1 cipher2 -c2 cipher3):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description='This program allows to carry out an Hastad Attack') parser.add_argument( '-n0', dest='n0', type=int, help='Modulus of the first RSA pulic key (decimal)', required=True) parser.add_argument( '-n1', dest='n1', type=int, help='Modulus of the second RSA pulic key (decimal)', required=True) parser.add_argument( '-n2', dest='n2', type=int, help='Modulus of the third RSA pulic key (decimal)', required=True) parser.add_argument('-e', dest='e', type=int, help='Common public exponent (decimal)', required=True) parser.add_argument('-c0', dest='c0', type=int, help='first ciphertext (decimal)', required=True) parser.add_argument('-c1', dest='c1', type=int, help='second ciphertext (decimal)', required=True) parser.add_argument('-c2', dest='c2', type=int, help='third ciphertext (decimal)', required=True) params = parser.parse_args(args) attack_object = Attack(params) attack_object.hastad() elif attack == "3": print("\n\t\t\t ***** Fermat Attack *****") try: args = input( "\n\t\t[*] Arguments ([-h] -n modulus -e exponent):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to carry out a Fermat Factorization') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-e', dest='e', type=int, help='RSA public key exponent', required=True) params = parser.parse_args(args) attack_object = Attack(params) attack_object.fermat() elif attack == "4": print("\n\t\t\t ***** Bleichenbacher Attack *****") try: args = input( "\n\t\t[*] Arguments ([-h] -n modulus -e exponent -c ciphertext --host hostname -p port --error error padding message):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to carry out a Bleichenbacher Attack') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus (int)', required=True) parser.add_argument('-e', dest='e', type=int, help='RSA public key exponent (int)', required=True) parser.add_argument('-c', dest='c', type=int, help='ciphertext (int)', required=True) parser.add_argument('--host', dest='host', type=str, help='hostname', required=True) parser.add_argument('-p', dest='port', type=int, help='port', required=True) parser.add_argument('--error', dest='error', type=str, help='Oracle Padding Error', required=True) params = parser.parse_args(args) attack_object = Attack(params) attack_object.bleichenbacher() elif attack == "5": print("\n\t\t\t ***** Common Modulus Attack *****") try: args = input( "\n\t\t[*] Arguments [-h] -n common modulus -e1 first exponent -e2 second exponent -c1 first cipher -c2 second cipher:\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to carry out a Common Modulus Attack') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-e1', dest='e1', type=int, help='First RSA public key exponent', required=True) parser.add_argument('-e2', dest='e2', type=int, help='Second RSA public key exponent', required=True) parser.add_argument('-c1', dest='c1', type=int, help='First ciphered text', required=True) parser.add_argument('-c2', dest='c2', type=int, help='Second ciphered text', required=True) params = parser.parse_args(args) attack_object = Attack(params) attack_object.comod() elif attack == "6": print("\n\t\t\t ***** Chosen Plaintext Attack *****") try: args = input( "\n\t\t[*] Arguments ([-h] -n modulus -e public_exponent -c ciphertext):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to carry out a Chosen Plaintext Attack') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-e', dest='e', type=int, help='first RSA public key exponent', required=True) parser.add_argument('-c', dest='c', type=int, help='ciphertext', required=True) params = parser.parse_args(args) params = parser.parse_args(args) attack_object = Attack(params) attack_object.chopla() elif attack == "a": print("\n\t\t\t ***** RSA Public Key parameters extraction *****") try: args = input("\n\t\t[*] Argument ([-h] -k K):\n\n\t\t\t").split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() if args[0] == '-k' and args[1] != '/': args[1] = getcwd() + "/" + args[1] parser = argparse.ArgumentParser( description= 'This program allows to extract the modulus and the exponent of an RSA public key (PEM)' ) parser.add_argument('-k', dest='k', type=str, help='path of the RSA public key', required=True) params = parser.parse_args(args) tool_object = Tool(params) tool_object.pubex() elif attack == "b": print("\n\t\t\t ***** RSA Private Key paramters extraction *****") try: args = input("\n\t\t[*] Argument ([-h] -k K):\n\n\t\t\t").split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() if args[0] == '-k' and args[1] != '/': args[1] = getcwd() + "/" + args[1] parser = argparse.ArgumentParser( description= 'This program allows to extract the parameters of an RSA private key (PEM)' ) parser.add_argument('-k', dest='k', type=str, help='path of the RSA private key', required=True) params = parser.parse_args(args) tool_object = Tool(params) tool_object.privex() elif attack == "c": print("\n\t\t\t ***** RSA Private Key constructor *****") try: args = input( "\n\t\t[*] Argument ([-h] -p first_factorization_element -q second_factorization_element -e public_exponent [-o output_file]):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to construct an RSA Private Key with its parameters' ) parser.add_argument('-p', dest='p', type=int, help='first element of the modulus factorization', required=True) parser.add_argument('-q', dest='q', type=int, help='second element of the modulus factorization', required=True) parser.add_argument('-e', dest='e', type=int, help='public exponent', required=True) parser.add_argument('-o', dest='o', type=str, help='output file') params = parser.parse_args(args) tool_object = Tool(params) tool_object.privkeyconstruct() elif attack == "d": print("\n\t\t\t ***** RSA Public Key constructor *****") try: args = input( "\n\t\t[*] Argument ([-h] -n modulus -e public_exponent [-o output_file]):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This program allows to construct an RSA Public Key with its parameters' ) parser.add_argument('-n', dest='n', type=int, help='modulus', required=True) parser.add_argument('-e', dest='e', type=int, help='public exponent', required=True) parser.add_argument('-o', dest='o', type=str, help='output file') params = parser.parse_args(args) tool_object = Tool(params) tool_object.pubkeyconstruct() elif attack == "e": print("\n\t\t\t ***** RSA Decipher *****") try: args = input( "\n\t\t[*] Argument ([-h] -n modulus -d private_exponent -c ciphertext):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This simple program allows to decipher a message using RSA') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-d', dest='d', type=int, help='RSA private key exponent', required=True) parser.add_argument('-c', dest='c', type=int, help='ciphertext', required=True) params = parser.parse_args(args) tool_object = Tool(params) tool_object.decipher() elif attack == "f": print("\n\t\t\t ***** RSA Encipher *****") try: args = input( "\n\t\t[*] Argument ([-h] -n modulus -e public_exponent -p plaintext):\n\n\t\t\t" ).split() except: print("\n\t\t\t[-] Argument Error: Please verify your inputs\n") exit() parser = argparse.ArgumentParser( description= 'This simple program allows to encipher a message using RSA') parser.add_argument('-n', dest='n', type=int, help='RSA public key modulus', required=True) parser.add_argument('-e', dest='e', type=int, help='RSA public key exponent', required=True) parser.add_argument('-p', dest='p', type=int, help='plaintext', required=True) params = parser.parse_args(args) tool_object = Tool(params) tool_object.encipher() else: choose("again")
from attacks import Attack # Initialize all attacks # ----------------------------------------------------------------------------------------- # # Fire type--------------------------- #new moves added blastburn = Attack(name='blast burn', attCategory='fire', baseDamage=150, pokemonLevel=0, baseCount=5, recoil=15, heal=0, accuracy=0.9) blazekick = Attack(name='blaze kick', attCategory='fire', baseDamage=85, pokemonLevel=0, baseCount=10, recoil=0, heal=0, accuracy=0.9) fierydance = Attack(name='fiery dance', attCategory='fire', baseDamage=80, pokemonLevel=0, baseCount=10, recoil=0, heal=0,
def main(): graph = graph_loader(graph_type='water', seed=1) params = { 'runs': 1, 'steps': 30, 'seed': 1, 'attack': 'rb_node', 'attack_approx': int(0.1 * len(graph)), 'plot_transition': True, 'gif_animation': True, 'gif_snaps': True, 'edge_style': None, 'node_style': None, 'fa_iter': 20 } print("Creating example visualization") a = Attack(graph, **params) a.run_simulation() node_attacks = ['rnd_node', 'id_node', 'rd_node', 'ib_node', 'rb_node'] edge_attacks = ['rnd_edge', 'id_edge', 'rd_edge', 'ib_edge', 'rb_edge'] params['runs'] = 10 params['steps'] = len(graph) - 1 params['plot_transition'] = False params['gif_animation'] = False params['gif_snaps'] = False print("Running node attacks") results = defaultdict(str) for attack in node_attacks: params['attack'] = attack if 'rb' in attack or 'ib' in attack: params['attack_approx'] = int(0.1 * len(graph)) else: params['attack_approx'] = None a = Attack(graph, **params) results[attack] = a.run_simulation() plot_results(graph, params['steps'], results, title='water:node-attacks_runs={}'.format(params['runs'])) print("Running edge attacks") results = defaultdict(str) for attack in edge_attacks: params['attack'] = attack if 'rb' in attack or 'ib' in attack: params['attack_approx'] = int(0.1 * len(graph)) else: params['attack_approx'] = None a = Attack(graph, **params) results[attack] = a.run_simulation() plot_results(graph, params['steps'], results, title='water:edge-attacks_runs={}'.format(params['runs']))