예제 #1
0
def addAdditionalItem(ltype, name, fileLocation):

    ltype = fileIO.addSlashIfAbsent(ltype)

    resname = "item"
    if fileLocation == RECIPES_CRAFTING:
        resname = "items"

    partialFileName = fileIO.genFileName([fileLocation, resname, ltype])

    # Tools here
    if (ltype == "tools/"):

        file = fileIO.genFileName([partialFileName, name + "_hoe.json"])
        genResFile(file, name)
        file = fileIO.genFileName([partialFileName, name + "_pickaxe.json"])
        genResFile(file, name)
        file = fileIO.genFileName([partialFileName, name + "_sword.json"])
        genResFile(file, name)
        file = fileIO.genFileName([partialFileName, name + "_shovel.json"])
        genResFile(file, name)

    # Armor here
    if (ltype == "armor/"):
        file = fileIO.genFileName([partialFileName, name + "_chest.json"])
        genResFile(file, name)
        file = fileIO.genFileName([partialFileName, name + "_leggings.json"])
        genResFile(file, name)
        file = fileIO.genFileName([partialFileName, name + "_boots.json"])
        genResFile(file, name)
def passwordValidator(password):
    score = 0
    # Too Short
    if len(password) < MIN_LENGTH:
        return score, SUGGESTIONS["underMinLength"], str(len(password))
    # Letters Only
    score += 1

    if onlyCharsInPassword(password, [('A', 'Z'), ('a', 'z')]):
        return score, SUGGESTIONS["lettersOnly"], ""

    # Letters and Numbers Only
    score += 1
    if onlyCharsInPassword(password, [('0', '9'), ('A', 'Z'), ('a', 'z')]):
        return score, SUGGESTIONS["lettersAndNumbersOnly"], ""

    # Common Numbers
    score += 1
    for number in WEAK_NUMBERS:
        pos = password.find(str(number))
        adjacentNumber = False
        if pos != -1:
            if (pos + 1) < len(password) and charInPassword(
                    password[pos + 1], [('0', '9')]):
                adjacentNumber = True
            if (pos - 1) > -1 and charInPassword(password[pos - 1],
                                                 [('0', '9')]):
                adjacentNumber = True
            if not adjacentNumber:
                return score, SUGGESTIONS["weakNumbers"], str(number)

    # Common Symbols
    score += 1
    asciiRange = []
    for symbol in WEAK_SYMBOLS:
        asciiRange.append((symbol, symbol))
    if charInPassword(password, asciiRange):
        return score, SUGGESTIONS["weakSymbols"], ""

    # Shannon entropy below threshold
    score += 1
    if shannonEntropy(password) < ENTROPY_THRESHOLD:
        return score, SUGGESTIONS["lowEntropy"], ""

    # Common Passwords in Password
    score += 1
    for length in range(MIN_LENGTH_RES, min(len(password), MAX_LENGTH_RES)):
        commonFileName = fileIO.genFileName(
            [THISDIR, RES, "passwords" + str(length) + ".txt"])
        if os.path.isfile(commonFileName):
            commonFile = open(commonFileName, "r")
            for commonPassword in commonFile:
                if password.lower().find(commonPassword.rstrip().lower()) > -1:
                    return score, SUGGESTIONS[
                        "commonPasswordInPassword"], commonPassword[:-1]

    score += 1
    return score, "Max Score", ""
예제 #3
0
def genDataRes(resType, resData):

    # For each 'line'
    for resDataLine in resData:
        ''' Does the dataLine have specific combinations of types. If yes, add 
        additional crafting recipes. eg. if block and slabs exist add 
        name_block_from_slab recipe
        '''
        FLAGS = setCraftingCombinationsFlags(resDataLine["types"])

        # For each name
        for nameIndex in range(len(resDataLine["names"])):
            name = resDataLine["names"][nameIndex]
            '''
            Add additional recipes 
            '''
            addCraftingCombinations(FLAGS, name)

            # For every type
            for rtype in resDataLine["types"]:
                resname, ltype, rtype = gesResNamespace(resType, rtype)
                print(DATA_MODNAME + ":" + resname[0] + ltype + name + "_" +
                      rtype)
                '''
                DATA CRAFTING RECIPES 
                '''
                # Ore does not have a crafting recipe
                if (not (rtype == "ore")):
                    file = fileIO.genFileName([
                        RECIPES_CRAFTING, resname[1], ltype,
                        name + "_" + rtype + ".json"
                    ])
                    genResFile(file, name)

                addAdditionalItem(ltype, name, RECIPES_CRAFTING)
                '''
                DATA LOOT TABLES
                '''
                # If block > blockstates
                if (resname[0] == "block"):
                    file = fileIO.genFileName([
                        LOOT_TABLES, resname[1], ltype,
                        name + "_" + rtype + ".json"
                    ])
                    genResFile(file, name)
예제 #4
0
sys.path.insert(0, os.path.dirname(THISDIR) + "/main")

import fileIO
import passwordFileBuilder
'''
Test functions in passwordFileBuilder.py up to passwords12.txt (if it works up to
that, it is likely to work far past it).

Some sensible assumptions have been made
here regarding scalability - add more tests if you don't think this is sufficient

Delete contents of resOut before running
'''
passwordFileBuilder.THISDIR = THISDIR
passwordFileBuilder.RES = "resOut"
RES = fileIO.genFileName([THISDIR, "resOut/"])


def test_passwordFileBuilder2():
    passwordFileBuilder.RES_IN = "resIn2"
    passwordFileBuilder.passwordFileBuilder()
    assert (sum(1 for line in open(RES + "passwords1.txt")) == 2)


# Again, if this passes, it can be assumed this will be accurate for other values
def test_passwordFileBuilder20():
    passwordFileBuilder.RES_IN = "resIn20"
    passwordFileBuilder.passwordFileBuilder()
    assert (sum(1 for line in open(RES + "passwords1.txt")) == 22)

예제 #5
0
def genAssetRes(resType, resData):
    # For each 'line'
    for resDataLine in resData:
        # For each name
        for nameIndex in range(len(resDataLine["names"])):
            name = resDataLine["names"][nameIndex]
            '''
            If it is a resource, generate the gem/ ingot, for items gen item 
            with name
            '''
            if (resType == "resources" or resType == "items"):
                print(name)
                file = fileIO.genFileName(
                    [ASSETS_MODELS, "item/", name + ".json"])
                genResFile(file, name)

            # For every type
            for rtype in resDataLine["types"]:
                resname, ltype, rtype = gesResNamespace(resType, rtype)
                print(DATA_MODNAME + ":" + resname[0] + ltype + name + "_" +
                      rtype)
                '''
                Blocks Only: 
                '''
                # If block > blockstates
                if (resname[0] == "block"):
                    file = fileIO.genFileName([
                        ASSETS_BLOCKSTATES, ltype, name + "_" + rtype + ".json"
                    ])
                    genResFile(file, name)

                    # Stairs and slabs have more block decorations
                    addAdditionalBlockModels(rtype, ltype, name)
                '''
                Items only 
                '''
                if (resname[0] == "item"):
                    addAdditionalItem(ltype, name, ASSETS_MODELS)
                '''
                Everything apart from items only (as they do not have a regular block 
                model "bars", "door", "lamp_inverted"). bars has variation models for the 
                block such as _noside and _noside alt. 
                '''
                ASSETS_MODELS_ITEMS_ONLY = ["bars", "door", "lamp_inverted"]
                if (rtype in ASSETS_MODELS_ITEMS_ONLY):
                    file = fileIO.genFileName([
                        ASSETS_MODELS, "item", ltype,
                        name + "_" + rtype + ".json"
                    ])
                    genResFile(file, name)
                else:
                    # (Everything else here)
                    file = fileIO.genFileName([
                        ASSETS_MODELS, resname[0], ltype,
                        name + "_" + rtype + ".json"
                    ])
                    genResFile(file, name)
                '''
                DATA FORGE 
                '''
                partialFileName = fileIO.genFileName(
                    [DATA_FORGE, resname[1], ltype])
                if (ltype == "decorations/"):
                    file = fileIO.genFileName(
                        [partialFileName, name + "_" + rtype + ".json"])
                    genResFile(file, name)
                elif (not (ltype == "tools/" or ltype == "armor/")):
                    file = fileIO.genFileName(
                        [partialFileName, name + ".json"])
                    genResFile(file, name)
예제 #6
0
def addAdditionalBlockModels(rtype, ltype, name):
    ltype = fileIO.addSlashIfAbsent(ltype)
    if (ltype == "decorations/"):
        RTYPE_SLABS = ["slab", "brick_slab"]
        RTYPE_STAIRS = ["stairs", "brick_stairs"]
        partialFileName = fileIO.genFileName([ASSETS_MODELS, "block", ltype])
        if (rtype in RTYPE_SLABS):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_top.json"])
            genResFile(file, name)
        if (rtype in RTYPE_STAIRS):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_inner.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_outer.json"])
            genResFile(file, name)
        if (rtype == "hopper"):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_side.json"])
            genResFile(file, name)
        if (rtype == "lamp"):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_on.json"])
            genResFile(file, name)
        if (rtype == "bars"):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_noside.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_noside_alt.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_post.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_side.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_side_alt.json"])
            genResFile(file, name)
        if (rtype == "door"):
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_bottom.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_bottom_hinge.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_top.json"])
            genResFile(file, name)
            file = fileIO.genFileName(
                [partialFileName, name + "_" + rtype + "_top_hinge.json"])
            genResFile(file, name)
def readConfig():
    data = fileIO.readJSON(fileIO.genFileName([THISDIR, CONFIG]))
    return data["minLength"], data["weakSymbols"], data["weakNumbers"], data[
        "suggestions"], data["minLengthRes"], data["maxLengthRes"], data[
            "entropy"]
shannon entropy
'''


def shannonEntropy(string):
    probChars = [
        float(string.count(char)) / len(string)
        for char in dict.fromkeys(list(string))
    ]
    return -sum([
        probChar * math.log(probChar) / math.log(2.0) for probChar in probChars
    ])


'''
Global variables are either block caps eg MIN_LENGTH or preceded with g_ eg
g_score
'''
if __name__ == "__main__":  # pragma: no cover
    MIN_LENGTH, WEAK_SYMBOLS, WEAK_NUMBERS, SUGGESTIONS, MIN_LENGTH_RES, MAX_LENGTH_RES, ENTROPY_THRESHOLD = readConfig(
    )
    g_passwordTokens = fileIO.fileToTokens(
        fileIO.genFileName([THISDIR, PASSWORDS]))
    for g_password in g_passwordTokens:
        pskClean = g_password.rstrip()
        g_score, g_suggestion, g_offense = passwordValidator(pskClean)
        print("password:"******"\tscore:", g_score)
        print("\tsuggestion:", g_suggestion)
        print("\toffense:", g_offense)
def test_genFileName():
    assert (fileIO.genFileName(["test", "file.txt"]) == "test/file.txt")