コード例 #1
0
def main(inputSDLScheme, configName, outputFile, outputUserDefFile):
    config = importlib.import_module(configName) # pkg.config
    SDLParser.masterPubVars = config.masterPubVars
    SDLParser.masterSecVars = config.masterSecVars
    SDLParser.generators = config.generators
    if hasattr(config, userFuncListName):
       userFuncList = getattr(config, userFuncListName)
    else:
       userFuncList = []

    SDLPreProcessor.SDLPreProcessor_main(inputSDLScheme, inputSDLScheme + PREPROCESSED_STRING, config)
    
    startTime = time.clock()
    (linesOfCodeFromKeygen, blindingFactors_NonLists, blindingFactors_Lists) = keygen(inputSDLScheme + PREPROCESSED_STRING, config)
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000
    #print("running time for keygen is ", runningTime)


    writeLOCFromKeygenToFile(linesOfCodeFromKeygen, inputSDLScheme + PREPROCESSED_STRING, config)
    cleanParseLinesOfCode()

    startTime = time.clock()
    codegen_PY.codegen_PY_main(inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".py", outputUserDefFile + ".py")
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000
    #print("running time for codegen python is ", runningTime)

    codegen_CPP.transformOutputList = transformOutputList

    startTime = time.clock()
    codegen_CPP.codegen_CPP_main(inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".cpp", userFuncList)
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000
コード例 #2
0
def add_user():
    '''
    This function checks if a username name already exists, 
    if not creates a new public key, private key pair using 
    keygen.py and stores the public key in public_keys.json
    '''
    # share_keys()
    json_req = request.get_json()
    username = json_req["username"]
    keys = {}
    with open('publickeys.json') as f:
        try:
            keys = json.load(f)
        except:
            pass

    if username in keys:
        return jsonify({
            "Message": "username already exists",
            "keys": keys[username]
        }), 200

    k = keygen(json_req["password"])
    keys[username] = {"A": k['A'], "B": k['B'], "p": k['p']}
    print("User", username)
    with open(f'secret_keys/{username}.txt', 'w+') as f:
        f.write(json_req["password"])

    with open('publickeys.json', 'w') as f:
        json.dump(keys, f)

    return jsonify({
        "Message": "New User added to keystore",
        "keys": keys[username]
    }), 200
コード例 #3
0
def main(SDL_Scheme):
    global setupFile, transformFile, decOutFile, userFuncsFile, assignInfo, varNamesToFuncs_All
    global varNamesToFuncs_Assign

    if ((type(SDL_Scheme) is not str) or (len(SDL_Scheme) == 0)):
        sys.exit(
            "codegen.py:  sys.argv[1] argument (file name for SDL scheme) passed in was invalid."
        )

    keygen(SDL_Scheme)
    astNodes = getAstNodes()
    assignInfo = getAssignInfo()
    varNamesToFuncs_All = getVarNamesToFuncs_All()
    varNamesToFuncs_Assign = getVarNamesToFuncs_Assign()

    if ((type(setupFileName) is not str)
            or (len(setupFileName) <= len(pySuffix))
            or (setupFileName.endswith(pySuffix) == False)):
        sys.exit("codegen.py:  problem with setupFileName in config.py.")

    if ((type(transformFileName) is not str)
            or (len(transformFileName) <= len(pySuffix))
            or (transformFileName.endswith(pySuffix) == False)):
        sys.exit("codegen.py:  problem with transformFileName in config.py.")

    if ((type(decOutFileName) is not str)
            or (len(decOutFileName) <= len(cppSuffix))
            or (decOutFileName.endswith(cppSuffix) == False)):
        sys.exit("codegen.py:  problem with decOutFileName in config.py.")

    setupFile = open(setupFileName, 'w')
    transformFile = open(transformFileName, 'w')
    decOutFile = open(decOutFileName, 'w')
    userFuncsFile = open(userFuncsFileName, 'w')

    getGlobalVarNames()

    addImportLines()
    addGroupObjGlobalVar()
    writeSDLToFiles(astNodes)
    writeMainFuncs()
    addGetGlobalsToUserFuncs()

    setupFile.close()
    transformFile.close()
    decOutFile.close()
    userFuncsFile.close()
コード例 #4
0
ファイル: codegen.py プロジェクト: JHUISI/auto-tools
def main(SDL_Scheme):
    global setupFile, transformFile, decOutFile, userFuncsFile, assignInfo, varNamesToFuncs_All
    global varNamesToFuncs_Assign

    if ( (type(SDL_Scheme) is not str) or (len(SDL_Scheme) == 0) ):
        sys.exit("codegen.py:  sys.argv[1] argument (file name for SDL scheme) passed in was invalid.")

    keygen(SDL_Scheme)
    astNodes = getAstNodes()
    assignInfo = getAssignInfo()
    varNamesToFuncs_All = getVarNamesToFuncs_All()
    varNamesToFuncs_Assign = getVarNamesToFuncs_Assign()

    if ( (type(setupFileName) is not str) or (len(setupFileName) <= len(pySuffix) ) or (setupFileName.endswith(pySuffix) == False) ):
        sys.exit("codegen.py:  problem with setupFileName in config.py.")

    if ( (type(transformFileName) is not str) or (len(transformFileName) <= len(pySuffix) ) or (transformFileName.endswith(pySuffix) == False) ):
        sys.exit("codegen.py:  problem with transformFileName in config.py.")

    if ( (type(decOutFileName) is not str) or (len(decOutFileName) <= len(cppSuffix) ) or (decOutFileName.endswith(cppSuffix) == False) ):
        sys.exit("codegen.py:  problem with decOutFileName in config.py.")

    setupFile = open(setupFileName, 'w')
    transformFile = open(transformFileName, 'w')
    decOutFile = open(decOutFileName, 'w')
    userFuncsFile = open(userFuncsFileName, 'w')

    getGlobalVarNames()

    addImportLines()
    addGroupObjGlobalVar()
    writeSDLToFiles(astNodes)
    writeMainFuncs()
    addGetGlobalsToUserFuncs()

    setupFile.close()
    transformFile.close()
    decOutFile.close()
    userFuncsFile.close()
コード例 #5
0
def process_des(filename, key, encryption):
	input_blocks = read_file(filename, encryption)
	
	# Return error if file is empty
	if not input_blocks:
		return 'file_empty_error'

	if input_blocks == 'not_encrypted_file':
		return 'not_encrypted_file'

	keys = keygen(key)

	if encryption:
		# Convert each block to binary if operation is encryption.
		input_blocks = [string_to_bin(x) for x in input_blocks]

		# Pad zeroes to the end, if last block has less than 64 bits.
		if len(input_blocks[-1]) < 64:
			input_blocks[-1] += '0' * (64 - len(input_blocks[-1]))

	if not encryption:
		# Reverse the key schedule if operation is decryption.
		keys = list(reversed(keys))

	encoded_text = ''
	for block in input_blocks:
		encoded_text += fiestel(block, keys)

	if encryption:
		# Return cipher text as binary.
		return encoded_text
	else:
		# Remove padded zeroes if any.
		for i in range(64, 0, -8):
			if encoded_text[-8:] == '0' * 8:
				encoded_text = encoded_text[:-8]
			else:
				break

		# Convert binary to normal string.
		return bin_to_string(encoded_text)
コード例 #6
0
ファイル: runAutoOutsrc.py プロジェクト: JHUISI/auto-tools
def main(inputSDLScheme, configName, outputFile, outputUserDefFile):
    config = importlib.import_module(configName)  # pkg.config
    SDLParser.masterPubVars = config.masterPubVars
    SDLParser.masterSecVars = config.masterSecVars
    SDLParser.generators = config.generators
    if hasattr(config, userFuncListName):
        userFuncList = getattr(config, userFuncListName)
    else:
        userFuncList = []

    SDLPreProcessor.SDLPreProcessor_main(inputSDLScheme, inputSDLScheme + PREPROCESSED_STRING, config)

    startTime = time.clock()
    (linesOfCodeFromKeygen, blindingFactors_NonLists, blindingFactors_Lists) = keygen(
        inputSDLScheme + PREPROCESSED_STRING, config
    )
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000
    # print("running time for keygen is ", runningTime)

    writeLOCFromKeygenToFile(linesOfCodeFromKeygen, inputSDLScheme + PREPROCESSED_STRING, config)
    cleanParseLinesOfCode()

    startTime = time.clock()
    codegen_PY.codegen_PY_main(
        inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".py", outputUserDefFile + ".py"
    )
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000
    # print("running time for codegen python is ", runningTime)

    codegen_CPP.transformOutputList = transformOutputList

    startTime = time.clock()
    codegen_CPP.codegen_CPP_main(
        inputSDLScheme + PREPROCESSED_STRING + config.finalSDLSuffix, outputFile + ".cpp", userFuncList
    )
    endTime = time.clock()
    runningTime = (endTime - startTime) * 1000