Exemplo n.º 1
0
def control():
    """
    Controla o fluxo das ações do usuário no programa

    variavel option: guarda o número da intenção do usuário quanto a ação no programa
    variavel input_option: guarda o número com o tipo de entrada 'digitação' ou 'arquivo txt'
    """

    while True:
        option = int(
            input(
                "What do you want to do?\n1. Generate public keys\n2. Encrypt\n3. Decrypt\n4. Kill this process\n::::  "
            ))
        input_option = 0
        final_content = ""
        if option == 4:
            print("bye")
            break
        elif option != 1:
            input_option = int(
                input("Do you want 1. to type or 2. send a file?\n:::: "))
        else:
            generate_public_keys()
            break

        if input_option == 1:
            message = input("Enter your message here: ")
            message = message.upper(
            )  #Caso a mensagem nao esteja em caixa alta
            if option == 2:
                n = int(input("Enter your first key (n): "))
                e = int(input("Enter your second key (e): "))
                final_content = first_option(message, n, e)
            elif option == 3:
                final_content = second_option(message)

        elif input_option == 2:
            name_file = input("What is the file name?\n:::: ")
            message = ""
            with open(name_file) as file:
                for i in file:
                    for k in i:
                        if k != '\n':
                            message += k
            if option == 2:
                n = int(input("Enter your first key (n): "))
                e = int(input("Enter your second key (e): "))
                final_content = first_option(message, n, e)
            elif option == 3:
                final_content = second_option(message)

        var = input("Do you want to save this message in a text file (y/n) ? ")
        if var == "y":
            savefile.save_file(final_content, "message.txt")

            print("\nDone!\n\n")
Exemplo n.º 2
0
def main():
    """
    Directs script to correct function based on inputs
    """

    input_args = parse_args()
    user_input = UserInputs(input_args)
    logger = get_module_logger(console=user_input.console)
    topics = user_input.apply_func()
    posts = Htmls(topics, user_input.sleep)
    res = posts.get_html_data(logger)
    Apiget(logger, topics=topics).get_out()
    savefile.save_file(res)
    TableUpdater(res, logger)
Exemplo n.º 3
0
def generate_public_keys():
    """
    Pede ao usuário os valores 'p', 'q' e 'e'
    para gerar as chaves.

    Salva um arquivo com as chaves públicas 'n' e 'e'.
    """
    while True:
        p = 0
        q = 0
        e = 0
        while True:
            p = int(input("Enter a prime number: "))
            if prime.is_prime(p):
                break
            print("Sorry, this number is not accepted.")

        while True:
            q = int(input("Enter another prime number: "))
            if prime.is_prime(q):
                break
            print("Sorry, this number is not accepted.")
        if p * q >= 27:
            break
        else:
            print("Sorry, P*Q is under to 27")

    phi = keys.calc_phi(p, q)

    while True:
        e = int(
            input(
                "Enter a number between 1 and {} which is prime relation to {}: "
                .format(phi, phi)))
        if mdc.mdc_euclides(e, phi) == 1:
            break
        print("Sorry, this number is not accepted.")

    n = keys.calc_n(p, q)

    savefile.save_file("n: {}\ne: {}".format(n, e), "public_keys.txt")
Exemplo n.º 4
0
def story():
    global current_room
    global time_entered
    global rug_moved
    global secret_uncovered
    global speed

    if items_dict["coffee"] in player["inventory"]:
        speed *= 1.5

    if len(quest_log.tip) > 0:
        if quest_log.tip[0].text == tips_text_list[1]:
            print("Welcome to the game. You should CHECK the room around you and find your notepad.")
            quest_log.remove_tip_by_text(tips_text_list[1])
            quest_log.add_tip(create_tip_from_file(9, npcs[0], current_time))
            print("""You sit at your desk in the 5th precinct of the Chicago PD waiting for the next crime to come over your desk,
and by chance it does, in the form of information coming in concerning "Wai Wu" the primary distributor for
the deadly drug Python, they're leaving town tonight and you have to catch them by 8 p.m. later today.
It's currently 2 p.m. and the pressure is on,

You look around the room and see numerous messy desks and a coffee machine
    """)

    if current_room == rooms["Drug Den"] and not rug_moved and not rooms["Drug Den"]["been"]:
        time_entered = get_time_from_str(current_time.display_time())

    if time_entered.hours != 0 and (diff_times(current_time, time_entered).mins >= 10 or diff_times(current_time, time_entered).hours >= 1) and not rug_moved and current_room == rooms["Drug Den"]:
        print("You swear the rug has been moved since last time.")
        rug_moved = True
        items_dict["rug"].interact = move_rug

    if items_dict["blueprints"] in player["inventory"]:
        secret_room()

    if secret_uncovered and current_room == rooms["Wai's House"]:
        print("It seems you must fight the bodyguard if you wish to enter the secret room.")
        print("Now you know where the secret room is, the guards see your newfound drive so reach for their weapons,")
        print("but this doesn't have to end in a firefight yet, not if you play it cool for the time being")
        print("Are you up for a fight, bearing in mind the weapons you have on you?")
        print("FIGHT the bodyguard for access")
        print("CONTINUE to look around the building as normal")
        print("What do you choose?")
        choice = None
        while choice != "fight" and choice != "continue":
            choice = input("> ").lower().strip()
            if choice == "fight":
                cls()
                success = fight_main(fighter_bodyguard)
                if not success:
                    print("""The guards take you down and you succumb to your wounds,
knowing that Wai will escape and ruin more lives""")
                    return False
                else:
                    print("You can save here if you wish:")
                    save_file()
                    rooms["Wai's House"]["exits"]["down"] = "Wai's Secret Room"
                    print("You make sure to have a gun on you before you head down to the secret chamber.")
                    if not items_dict["gun"] in player["inventory"]:
                        player["inventory"].append(items_dict["gun"])
                    current_room = rooms["Wai's Secret Room"]

    if current_room == rooms["Wai's Secret Room"] and current_time.hours < 20:
        cls()
        print("""You look to the middle of the room and behind the desk you see a dark figure
collecting documents and money from a safe. They turn round and they disrobe to reveal
your dearest friend: Jing Wu.
“Aha, You didn’t expect this turn of events did you Sidorov, I was under your nose this
entire time and you couldn’t see it.”
You take out your gun and try to talk Jing down;
“Jing, how could you do this to so many people? I can’t believe I’ve been so blind”.
She jumps backwards and brings out a gun.""")
        quest_log.add_tip(create_tip_from_file(11, "Your subconscious", current_time))
        success = fight_main(fighter_wai)
        if not success:
            print("""Seemingly out of nowhere Jing has a well placed shot that manages to find your torso.
As you begin to bleed out out she collects the remainder of her documents.
“Better luck next time, Sidorov...” she sneers as she locks the secret hatch and leaves you for dead.
You’ve failed and you live with your mistakes before you slowly die""")
            return False
        else:
            print("""You eventually manage to shoot Jing in the shoulder and she collapses to the ground.
You handcuff her. “You’ll regret this Kirill, believe me” she shouts.
You call in backup to bag all the evidence and to take her back to the station.
With the ledger and the evidence contained in the room
you know that “Wai Wu” is going down for a long time""")
            return "won"
    elif current_room == rooms["Wai's Secret Room"] and current_time.hours >= 20:
        print("""You see that the safe behind the desk has already been pillaged and you realise
that you’ve been too late, Wai Wu has moved on to the next city and you’ve failed your assignment.
You feel the shame of knowing you could’ve caught them and that you may never hear of them again
        """)
        quest_log.add_tip(create_tip_from_file(12, "Your subconscious", current_time))
        return False

    return True
Exemplo n.º 5
0
def execute_command(command):
    cls()
    continue_story = False
    global current_room

    if 0 == len(command):
        return

    if command[0] == "go":
        if len(command) > 1:
            execute_go(command[1])
            continue_story = True
        else:
            print("Go where?")

    elif command[0] == "take":
        if len(command) > 1:
            execute_take(command[1])
            current_time.incr_time(0, 1 / speed)
        else:
            print("Take what?")

    elif command[0] == "check":
        current_room["checked"] = True
        if current_room == rooms["Warehouse"] or current_room == rooms["Warehouse Upper"]:
            current_time.incr_time(0, 30 / speed)
        else:
            current_time.incr_time(0, 10 / speed)

    elif command[0] == "question":
        success = False
        for characters in npcs:
            if characters.id == command[1]:
                success = True
                execute_question(characters)
                current_time.incr_time(0, 10 / speed)
        if not success:
            print("Question who?")

    elif command[0] == "profile":
        if len(command) > 1:
            execute_profile(command[1])
            current_time.incr_time(0, 2 / speed)
        else:
            print("Question who?")

    elif command[0] == "view":
        if items_dict["notepad"] in player["inventory"]:
            quest_log.print_tips()
        else:
            print("You should pick up your journal from your desk.")

    elif command[0] == "inspect":
        if len(command) > 1:
            execute_inspect(command[1])
        else:
            print("Inspect what?")

    elif command[0] == "interact":
        if len(command) > 1:
            execute_interact(command[1])
            current_time.incr_time(0, 2 / speed)
        else:
            print("Interact with what?")

    elif command[0] == "save":
        save_file()

    elif secret_uncovered and current_room == rooms["Wai's House"] and command[0] == "fight":
        return

    elif command[0] == "load":
        load_file()
        continue_story = True

    else:
        print("This makes no sense.")

    return_list = continue_story
    return return_list
Exemplo n.º 6
0
 def get_out(self):
     """Save file in api_results.json"""
     data = self.get_apinfo()
     save_file(data, filename=utils["API_FILE"])