Advertisement
Guest User

Untitled

a guest
Jun 29th, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.21 KB | None | 0 0
  1. import random
  2. import sys
  3. import time
  4. import re
  5.  
  6. ip = re.compile(r"^((?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$")
  7.  
  8.  
  9. def is_ip(a):
  10.     return ip.match(a) is not None
  11.  
  12.  
  13. def sleep(s):
  14.     time.sleep(s + (0.1 * len(installed())))
  15.  
  16.  
  17. def bruteforce(a, b):
  18.     global last
  19.     if not is_ip(str(a)): raise SyntaxError('hey, ur not haking if u dont use ip!!!')
  20.     optional_print('Bruteforcing', a)
  21.     sleep(random.randint(1, 5))
  22.     variables[a] = b
  23.     last = b
  24.     optional_print('Finished bruteforcing', a)
  25.     return b
  26.  
  27.  
  28. def install(a):
  29.     if a not in package_signatures.keys(): raise SyntaxError(f'man ur dumb as hell if u dont know that "{a}" is not even a package')
  30.     optional_print(f"Installing package '{a}'. Please wait...")
  31.     sleep(4)
  32.     signatures[a] = package_signatures[a]
  33.     commands.append(a)
  34.     optional_print(f"Successfully installed '{a}'!")
  35.  
  36.  
  37. def uninstall(a):
  38.     if a not in installed(): raise SyntaxError("lmao what are you uninstalling, if u keep doing that, ill uninstall u")
  39.     optional_print(f"Uninstalling package '{a}'. Please wait...")
  40.     sleep(1)
  41.     del signatures[a]
  42.     commands.remove(a)
  43.     optional_print(f"Successfully uninstalled '{a}'")
  44.  
  45.  
  46. def call_signature(a, *args, **kwargs):
  47.     sleep(0)
  48.     return a(*args, **kwargs)
  49.  
  50.  
  51. def check_command(a):
  52.     if a != 0: goto_command(current_line * 2)
  53.  
  54.  
  55. def goto_command(l):
  56.     global current_line
  57.     current_line = l - 1
  58.  
  59.  
  60. def ping(a):
  61.     sleep(1)
  62.     b = variables[a]
  63.     return b
  64.  
  65.  
  66. def sum_command(a):
  67.     if last is not None: return a + last
  68.     return a
  69.  
  70.  
  71. def installed():
  72.     return tuple(set(commands) - set(original))
  73.  
  74.  
  75. def optional_print(*args, **kwargs):
  76.     if 'silence' not in flags: print(*args, **kwargs)
  77.  
  78.  
  79. def flag_appender(flag_name, wait_time=0):
  80.     if flag_name not in flags:
  81.         optional_print(f"Appending flag '{flag_name}'")
  82.         sleep(wait_time)
  83.         flags.append(flag_name)
  84.     else:
  85.         flags.remove(flag_name)
  86.         optional_print(f"Removing flag '{flag_name}")
  87.         sleep(wait_time)
  88.  
  89.  
  90. commands = ["install", "uninstall"]
  91. original = tuple(commands)
  92. flags = []
  93. variables = {}
  94. last = None
  95. package_signatures = {"newline": lambda: print(), "show": lambda a: print(a, end=""), "input": lambda: int(input()),
  96.                       "inputstr": lambda: input(), "bruteforce": bruteforce, "ping": ping,
  97.                       "sum": sum_command, "negate": lambda a: -a,
  98.                       "goto": goto_command, "check": check_command,
  99.                       "silence": lambda: flag_appender("silence", 5), "turtlejam": lambda: flag_appender("turtlejam", 1)}
  100. signatures = {"install": install, "uninstall": uninstall}
  101.  
  102.  
  103. def how_do_i_parse_this_AAAA(line: str, execute_commands: bool = True, max_params: int = 999):
  104.     done = []
  105.     while len(line) > 0 and len(done) < max_params:
  106.         if line.startswith('"'):
  107.             i = line[1:].find('"')
  108.             done.append(parse_simple(line[:i + 2]))
  109.             line = line[i + 2:]
  110.         split = line.split()
  111.         if len(split) == 0: continue
  112.         if split[0] in commands:
  113.             if execute_commands: done.append(parse_command(line))
  114.             else: done.append(line)
  115.             continue
  116.         done.append(parse_simple(split[0]))
  117.         line = line[len(split[0]) + 1:]
  118.     return done[:max_params]
  119.  
  120.  
  121. def parse_command(line: str, stop_if_not_command: bool = False):
  122.     split = line.split()
  123.     if len(split) > 0 and split[0] in commands:
  124.         joined = ' '.join(split[1:])
  125.         args = how_do_i_parse_this_AAAA(joined, True)
  126.         return call_signature(signatures[split[0]], *args)
  127.     elif stop_if_not_command or line.isspace() or not line:
  128.         return None
  129.     return parse_simple(line)
  130.  
  131.  
  132. def parse_num(lit):
  133.     if 'turtlejam' in flags:
  134.         if lit == 'noturtle': return 0
  135.         elif 'turtle' in lit:
  136.             count = lit.count('turtle')
  137.             if count * 6 < len(lit): raise Exception
  138.             return count
  139.         raise Exception
  140.     return int(lit)
  141.  
  142.  
  143. def generate_error_message(exception: Exception):
  144.     print(f"\n\t{exception.__class__.__name__}, line {current_line}: {' '.join(exception.args)}")
  145.     exit()
  146.  
  147.  
  148. def parse_simple(line: str):
  149.     split = line.split()
  150.     if split[0].startswith('"'):
  151.         end_quote_index = line[1:].find('"')
  152.         if end_quote_index == -1:
  153.             generate_error_message( SyntaxError('ur not real haker cuz you literally missed a quote') )
  154.         return line[1:end_quote_index + 1]
  155.     try:
  156.         if len(split) > 1: raise Exception
  157.         return parse_num(split[0])
  158.     except:
  159.         if is_ip(split[0]): return split[0]
  160.         generate_error_message( SyntaxError(f"can u explain the hell is '{line}' it's not even a haker term") )
  161.  
  162.  
  163. argv_req = False
  164. if len(sys.argv) < 2 and argv_req:
  165.     print('provide a file to start haking!1!!!!')
  166.     exit()
  167. code = open(sys.argv[1] if argv_req else 'd.hs', 'r').read().strip('\n')
  168. split = code.split('\n')
  169. total_lines = len(split)
  170. current_line = 0
  171.  
  172. while True:
  173.     current_line += 1
  174.     if current_line < 1 or current_line > total_lines: break
  175.     parse_command(split[current_line - 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement