Exemple #1
0
 def start(self):
     path = get_file(self.config.path)
     lines = [
         line.strip() for line in File(path).read().splitlines() if line
     ]
     random.shuffle(lines)
     lines = lines[:self.config.num]
     while True:
         q.clear()
         self.miss = set()
         self.okay = set()
         for num, line in enumerate(lines, 1):
             q.echo("%s of %s" % (num, len(lines)))
             self._ask(line)
             q.hrule()
         fmiss = File(self.config.path, MISSED_VOCAB)
         for miss in self.miss:
             fmiss.append(miss + "\n")
         q.echo("Results:")
         q.echo(f"Correct = {len(self.okay)}")
         q.echo(f"Missed = {len(self.miss)}")
         q.hrule()
         if not q.ask_yesno("Retry?", default=False):
             break
         if self.miss and q.ask_yesno("Missed only?", default=True):
             lines = list(self.miss)
         if q.ask_yesno("Shuffle?", default=True):
             random.shuffle(lines)
             lines = lines[:self.config.num]
Exemple #2
0
def makeissue(repository, fragment, html_url, lineinfo):
    print Fore.RED + fragment
    print(Style.RESET_ALL)
    body = """
    The Cyber Defense Center found cleartext credentials in this repository.

    %s


    %s

    %s
    """ % (fragment, html_url, lineinfo)
    if qprompt.ask_yesno("Is this a valid result?", dft="n"):
        print "Creating Github Issue...."
        g = Github(base_url="https://github.$ENTERPRISE.com/api/v3",
                   login_or_token="")
        repo = g.get_repo(repository)
        createissue = repo.create_issue(
            title="Security: Cleartext Credentials Found", body=body)
        jiracomment = "Created issue #%s for %s repository" % (
            createissue.number, repository)
        print jiracomment
        jira = JIRA('https://jira.$ENTERPRISE.com',
                    basic_auth=(jirausername, jirapassword))
        issue = jira.issue("ATTACKPT-62")
        jira.add_comment(issue, jiracomment)
        qprompt.pause()
        qprompt.clear()
    qprompt.clear()
Exemple #3
0
def decision_round(player):
    s = "Your hand: "
    for card in player.memory["cards"]:
        s += str(card) + " "
    s += " |  "
    s += "Hand value: " + str(player.memory["cards_val"])
    s += "\n"
    qprompt.info(s)

    # Allow user to make a decision in the game
    if player.memory["cards_val"] >= 21:
        options = ["Stay", "Exit"]
        item = qprompt.enum_menu(options).show(header="OPTIONS:")
        print("Selected " + options[int(item)-1] + ".")
        qprompt.hrule()
        return options[int(item)-1]
    else:
        options = ["Hit","Stay","Exit"]
        if player.memory["no_cards"] == 2 and SPLIT_FLAG == False:
            options.append("Double down")
            if player.memory["cards"][0].number == player.memory["cards"][1].number:
                options.append("Split")
        item = qprompt.enum_menu(options).show(header="OPTIONS:")
        print("Selected " + options[int(item)-1] + ".")
        qprompt.clear()
        return options[int(item)-1]
Exemple #4
0
def betting_round(player):
    # Make bets
    bet = qprompt.ask_int("Enter a bet amount less than your bank value of " + str(player.memory["bank"]), valid=lambda x: x <= player.memory["bank"])
    player.memory["bank"] -= bet
    player.memory["bet"] = bet
    qprompt.info("Betted " + str(bet))
    qprompt.pause()
    qprompt.clear()
Exemple #5
0
def payout_round(deck, player):
    # decide how much the player should be payed out based on a random dealer draw
    qprompt.clear()
    payout = 0
    dealer_memory = {
        "bank": DEFAULT_BANK,
        "bet": 0,
        "no_cards": 0,
        "cards": [],
        "cards_val": 0,
        "status": "NORMAL",
        "vals": []
    }
    # the dealer's bank doesn't matter, we can keep reinstantiating
    dealer = Player(ids="Dealer", update=blackjack_update, memory=dealer_memory)
    dealer.receive(deck.draw())
    dealer.receive(deck.draw())

    while dealer.memory["cards_val"] <= 16:
        dealer.receive(d.draw())

    for value in player.memory["vals"]:
        if dealer.memory["cards_val"] > 21:
            if value == 21:
                payout += player.memory["bet"]*2.5
            elif value < 21:
                payout += player.memory["bet"]*2
        elif dealer.memory["cards_val"] == 21:
            payout += 0
        elif value <= 21:
            if value > dealer.memory["cards_val"]:
                payout += player.memory["bet"]*2
                if value == 21:
                    payout += player.memory["bet"]*0.5
            elif value == dealer.memory["cards_val"]:
                payout += player.memory["bet"]
            else:
                payout += 0

    qprompt.info("DEALER GOT: " + str(dealer.memory["cards_val"]))
    qprompt.info("PAYOUT: " + str(payout))
    player.memory["bet"] = 0
    player.memory["bank"] += payout
    player.discard(player.memory)
    player.memory["cards_val"] = 0
    player.memory["cards"] = []
    player.memory["no_cards"] = 0
    player.memory["vals"] = []
    qprompt.pause()
    qprompt.clear()
Exemple #6
0
def makeissue(repository, fragment, html_url, lineinfo):
    print Fore.RED + fragment

    print(Style.RESET_ALL)
    body = """
    %s

    %s

    %s
    """ % (fragment, html_url, lineinfo)
    if qprompt.ask_yesno("Is this a valid result?", dft="n"):
        resulttext.append(body)
        qprompt.pause()
        qprompt.clear()
    qprompt.clear()
Exemple #7
0
def makeissue(repository, fragment, html_url, lineinfo):
    f = open("findings.txt", "a+")
    print fragment
    print "\n"
    body = """
    Code Fragment:
    %s\n
    Code Location:\n
    %s
    Lines:\n
    %s
    """ % (fragment, html_url, lineinfo)
    if qprompt.ask_yesno("Is this a valid result?", dft="n"):
        f.write(body)
        qprompt.clear()
        f.close()
    qprompt.clear()
    f.close()
Exemple #8
0
 def learn(self):
     path = get_file(self.config.path)
     lines = [
         line.strip() for line in File(path).read().splitlines() if line
     ]
     random.shuffle(lines)
     lines = lines[:self.config.num]
     q.clear()
     for num, line in enumerate(lines, 1):
         q.echo("%s of %s" % (num, len(lines)))
         qst, ans = self._get_qst_ans(line)
         vld = Practice._get_valid(ans)
         q.alert(qst.rand)
         q.alert(ans.rand)
         talk(qst.rand, qst.lang.name.short)
         talk(ans.rand, ans.lang.name.short, slow=True)
         rsp = ""
         while rsp not in vld:
             rsp = q.ask_str("").lower().strip()
         q.clear()
         flush_input()
         talk(ans.rand, ans.lang.name.short, slow=True)
         q.echo("%s of %s" % (num, len(lines)))
         ans.lang.hint = len(ans.rand) // 4
         rsp = ""
         while rsp not in vld:
             msg = Practice._get_msg_base(qst) + Practice._get_msg_hint(ans)
             q.alert(msg)
             rsp = q.ask_str("").lower().strip()
             ans.lang.hint += 1
         q.echo("[CORRECT] " + ans.text)
         talk(ans.rand, ans.lang.name.short, wait=True)
         q.clear()
Exemple #9
0
    player.memory["bank"] += payout
    player.discard(player.memory)
    player.memory["cards_val"] = 0
    player.memory["cards"] = []
    player.memory["no_cards"] = 0
    player.memory["vals"] = []
    qprompt.pause()
    qprompt.clear()


d = Deck()
player = Player(ids="You", update=blackjack_update, memory=blackjack_memory)

# main loop
while (not EXIT_FLAG):
    qprompt.clear()
    betting_round(player)

    qprompt.info("DEALING CARDS...")
    player.receive(d.draw())
    player.receive(d.draw())

    while (not STAY_FLAG ) and (not EXIT_FLAG):

        action = decision_round(player)

        if action == "Hit":
            player.receive(d.draw())
        elif action == "Double down":
            player.memory["bank"] -= player.memory["bet"]
            player.memory["bet"] += player.memory["bet"]