当前位置: 首页>>代码示例>>Python>>正文


Python ProgressBar.show方法代码示例

本文整理汇总了Python中ProgressBar.ProgressBar.show方法的典型用法代码示例。如果您正苦于以下问题:Python ProgressBar.show方法的具体用法?Python ProgressBar.show怎么用?Python ProgressBar.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgressBar.ProgressBar的用法示例。


在下文中一共展示了ProgressBar.show方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from ProgressBar import ProgressBar [as 别名]
# 或者: from ProgressBar.ProgressBar import show [as 别名]
def main():

	# Comprobación de errores de entrada #
	if len(sys.argv) < 3:
		uso()

	mode = sys.argv[1]
	ifile = sys.argv[2]

	if mode not in ['-e', '-d'] or not os.path.exists(ifile):
		uso()

	try:
		with open(ifile, 'rb') as f:
			inf = f.read()
	except:
		print ("Error leyendo el archivo de entrada.")
		sys.exit()

	Nb = 4
	Nk = 4
	Nr = 10
	if len(sys.argv) > 3 and sys.argv[3] == '-192':
		Nk = 6
		Nr = 12
	elif len(sys.argv) > 3 and sys.argv[3] == '-256':
		Nk = 8
		Nr = 14
	######################################

	#key = getpass("Introduzca una contraseña de cifrado de {0} cifras hexadecimales: ".format(Nb * Nk * 2))
	key = raw_input("Introduzca una contraseña de cifrado de {0} cifras hexadecimales: ".format(Nb * Nk * 2))

	if len(key) < Nb * Nk * 2:
		print ("Contraseña demasiado corta. Rellenando con \'0\' hasta alcanzar una longitud de {0} cifras.".format(Nb * Nk * 2))
		key += "0"* (Nb * Nk * 2 - len(key))
	elif len(key) > Nb * Nk * 2:
		print ("Contraseña demasiado larga. Conservando únicamente las primeras {0} cifras.".format(Nb * Nk * 2))
		key = key[:Nb * Nk * 2]

	key = process_key(key, Nk)

	expanded_key = expand_key(key, Nb, Nk, Nr)

	if mode == '-e':
		ofile = ifile + '.aes'
	elif mode == '-d' and ifile.endswith('.aes'):
		ofile = ifile[:-4]
		if os.path.exists(ofile):
			spam = raw_input('El archivo "{0}" ya existe. ¿Sobreescribir? [s/N]'.format(ofile))
			if spam.upper() != 'S':
				ofile = raw_input('Introduzca nuevo nombre de archivo: ')
	else:
		ofile = ifile

	pb = ProgressBar(len(inf), 0)


	output = None

	if mode == '-e': # Encript
		inf = padding(inf, Nb)

	while inf:
		block, inf = get_block(inf, Nb)

		c = pb.update(len(inf))
		if c: pb.show()

		if mode == '-e': # Encript
			block = Cipher(block, expanded_key, Nb, Nk, Nr)
		elif mode == '-d': # Decript
			block = InvCipher(block, expanded_key, Nb, Nk, Nr)

		block = prepare_block(block)
		if output: output += block
		else: output = block

	if mode == '-d': # Decript
		output = unpadding(output, Nb)


	with open(ofile, 'wb') as f:
		#for block in output: f.write(block)
		f.write(output)

	print('')
	sys.exit()
开发者ID:frankdiox,项目名称:Cryptography-for-Network-Security,代码行数:90,代码来源:P4.py

示例2: main

# 需要导入模块: from ProgressBar import ProgressBar [as 别名]
# 或者: from ProgressBar.ProgressBar import show [as 别名]
def main():

    if len(sys.argv) > 1 and sys.argv[1] == "-demo":
        demo()

    if len(sys.argv) < 3:
        help()

    mode = sys.argv[1]
    ifile = sys.argv[2]

    if mode not in ["-e", "-d"] or not os.path.exists(ifile):
        help()

    try:
        with open(ifile, "rb") as f:
            inf = f.read()
    except:
        print("Error while trying to read input file.")
        sys.exit()

    Nb = 4
    Nk = 4
    Nr = 10

    eggs = "".join(sys.argv[3:])

    spam = eggs.find("-c")
    if spam > -1 and eggs[spam + 2 : spam + 5] in ["128", "192", "256"]:
        Nk = int(eggs[spam + 2 : spam + 5]) // 32

    Nr = Nk + 6

    key = raw_input("Enter a key, formed by {0} hexadecimal digits: ".format(Nk * 8))
    key = key.replace(" ", "")

    if len(key) < Nk * 8:
        print("Key too short. Filling with '0'," "so the length is exactly {0} digits.".format(Nk * 8))
        key += "0" * (Nk * 8 - len(key))

    elif len(key) > Nk * 8:
        print("Key too long. Keeping only the first {0} digits.".format(Nk * 8))
        key = key[: Nk * 8]

    key = process_key(key, Nk)

    expanded_key = KeyExpansion(key, Nb, Nk, Nr)

    if mode == "-e":
        ofile = ifile + ".aes"
    elif mode == "-d" and (ifile.endswith(".aes") or ifile.endswith(".cif")):
        ofile = ifile[:-4]
    else:
        ofile = raw_input("Enter the output filename: ")
        path_end = ifile.rfind("/")
        if path_end == -1:
            path_end = ifile.rfind("\\")
        if path_end != -1:
            ofile = ifile[: path_end + 1] + ofile

    if os.path.exists(ofile):
        spam = raw_input('The file "{0}" already exists. Overwrite? [y/N] '.format(ofile))
        if spam.upper() != "Y":
            ofile = raw_input("Enter new filename: ")

    pb = ProgressBar(len(inf), 0)

    output = None

    if mode == "-e":  # Encrypt
        inf = padding(inf, Nb)

    print("")
    while inf:
        block, inf = get_block(inf, Nb)

        c = pb.update(len(inf))
        if c:
            pb.show()

        if mode == "-e":  # Encrypt
            block = Cipher(block, expanded_key, Nb, Nk, Nr)
        elif mode == "-d":  # Decript
            block = InvCipher(block, expanded_key, Nb, Nk, Nr)

        block = prepare_block(block)
        if output:
            output += block
        else:
            output = block

    if mode == "-d":  # Decript
        output = unpadding(output, Nb)

    with open(ofile, "wb") as f:
        f.write(output)

    print("")
    sys.exit()
开发者ID:pcaro90,项目名称:Python-AES,代码行数:101,代码来源:AES.py


注:本文中的ProgressBar.ProgressBar.show方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。