Best Python code snippet using avocado_python
nmap_db_parser_responses_format.py
Source:nmap_db_parser_responses_format.py
...14def hex_value (string):15 if "-" in string:16 values = string.split("-")17 if values[0]==values[1]:18 return string_to_hex(values[0])19 else:20 return (string_to_hex(values[0]),string_to_hex(values[1]))21 # return [string_to_hex(values[0]),string_to_hex(values[1])]22 # return random.randint(string_to_hex(values[0]),string_to_hex(values[1]))23 elif ">" in string : # FEW CASES24 return string_to_hex(string[1:])25 # return (">",string_to_hex(string[1:]))26 # return [string_to_hex(string[1:]),sys.maxsize]27 # return string_to_hex(string[1:])28 #return random.randint(string_to_hex(string[1:]),sys.maxsize)29 elif "<" in string: # NOT EXIST30 return ("<",string_to_hex(string[1:]))31 # return [-1,string_to_hex(string[1:])]32 # return string_to_hex(string[1:])33 # return random.randint(-1,string_to_hex(string[1:]))34 elif string == "":35 return -136 else:37 return string_to_hex(string)38# %%39def TI_CI_II (string):40 if string == "Z":41 return [1,-1]42 elif string == "RD":43 return [2,-1]44 elif string == "RI":45 return [3,-1]46 elif string == "BI":47 return [4,-1]48 elif string == "I":49 return [5,-1]50 elif string == "":51 return [-1,-1]...
string_to_hex.py
Source:string_to_hex.py
1from sys import argv2option_handle_list = ['--help', '--reverse']3options = {}4def help():5 print("Usage: python string_to_hex [OPTION]... [BYTES]... [STRING]...")6 print("substitution the string with hexadecimal.")7 print()8 print("==================== for instance ====================")9 print(" > 'flag' -> 0x66, 0x6c, 0x61, 0x67 = 0x67616c66 ")10 print()11 print(" > python string_to_hex.py flag -> 0x67616c66")12 print()13 print(" > python string_to_hex.py 8 flag -> 0x0000000067616c66")14 print()15 print(" > python string_to_hex.py --reverse 8 0x0000000067616c66 -> reversed : flag")16 print()17 print("======================= OPTION =======================")18 print("--help : show this programe option and explain")19 print()20 print("--reverse : Converts hexadecimal to string.")21 print()22if len(argv) == 3:23 if argv[1] in option_handle_list:24 option = option_handle_list[option_handle_list.index(argv[1])].replace("--", "")25 if option == 'help':26 help()27 elif option == 'reverse':28 print("Usage: python string_to_hex --reverse [BYTES]... [STRING]...")29 30 elif '--' in argv[1]:31 option = argv[1].replace("--", "")32 print(f"{argv[0]}: invalid option -- '{option}' ")33 print("Try 'python string_to_hex --help' for more information.")34 else:35 ann = [str(hex(ord(i)))[2:] for i in argv[2]]36 ann.reverse()37 print(f"input : {argv[2]}")38 try:39 result = "".join(ann)40 result = "0x" + ((int(argv[1]) * 2) - len(result)) * "0" + "".join(ann)41 except ValueError:42 print("Try 'python string_to_hex --help' for more information.")43 print("Please put in the correct value")44 exit(0)45 print(result)46 47elif len(argv) >= 3:48 for option_handle in option_handle_list:49 options[option_handle[2:]] = argv[argv.index(option_handle) + 1] if option_handle in argv else None50 51 for a, b in options.items():52 if b != None:53 option = a54 55 if options['reverse'] != None:56 if not '0x' in argv[3][0:2]:57 print("Usage: python string_to_hex --reverse [BYTES]... [STRING]...")58 print("Please put in the correct value")59 exit(0)60 try:61 _input = argv[3].replace("0x", "")62 arr = ["0x" + _input[i:i+2] for i in range(0, len(_input), 2)]63 arr.reverse()64 print(f"input : {argv[3]}")65 print(f"reversed : "+"".join(chr(int(i, 16)) for i in arr))66 except ValueError:67 print("Usage: python string_to_hex --reverse [BYTES]... [STRING]...")68 print("Please put in the correct value")69 elif '--' in argv[1]:70 option = argv[1].replace("--", "")71 print(f"{argv[0]}: invalid option -- '{option}' ")72 print("Try 'python string_to_hex --help' for more information.")73 else:74 print("Usage: python string_to_hex --reverse [BYTES]... [STRING]...")75 exit(0)76elif len(argv) == 2:77 if argv[1] in option_handle_list:78 option = option_handle_list[option_handle_list.index(argv[1])].replace("--", "")79 if option == 'help':80 help()81 elif option == 'reverse':82 print("Usage: python string_to_hex --reverse [BYTES]... [STRING]...")83 84 elif '--' in argv[1]:85 option = argv[1].replace("--", "")86 print(f"{argv[0]}: invalid option -- '{option}' ")87 print("Try 'python string_to_hex --help' for more information.")88 else:89 ann = [str(hex(ord(i)))[2:] for i in argv[1]]90 ann.reverse()91 print(f"input : {argv[1]}")92 result = "0x" + "".join(ann)93 print(result)94else:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!