io - Python: Trying to speed up a program that is running very slow -


so, program parses e-mail address , plain-text password text file. then, runs them through few encryption routines , appends encrypted text onto end of e-amil address:password entry in new file.

import io crypto.cipher import aes import base64 import struct  def str_to_a32(b):   if len(b) % 4:     b += '\0' * (4 - len(b) % 4)   return struct.unpack('>%di' % (len(b) / 4), b)   def a32_to_str(a):   return struct.pack('>%di' % len(a), *a)   def aes_cbc_encrypt(data, key):   encryptor = aes.new(key, aes.mode_cbc, '\0' * 16)   return encryptor.encrypt(data)   def aes_cbc_encrypt_a32(data, key):   return str_to_a32(aes_cbc_encrypt(a32_to_str(data), a32_to_str(key)))  def base64urlencode(data):   data = base64.b64encode(data)   search, replace in (('+', '-'), ('/', '_'), ('=', '')):     data = data.replace(search, replace)   return data   def a32_to_base64(a):   return base64urlencode(a32_to_str(a))   def stringhash(s, aeskey):   s32 = str_to_a32(s)   h32 = [0, 0, 0, 0]   in xrange(len(s32)):     h32[i % 4] ^= s32[i]   _ in xrange(0x4000):     h32 = aes_cbc_encrypt_a32(h32, aeskey)   return a32_to_base64((h32[0], h32[2]))   def prepare_key(a):   pkey = [0x93c467e3, 0x7db0c7a4, 0xd1be3f81, 0x0152cb56]   _ in xrange(0x10000):     j in xrange(0, len(a), 4):       key = [0, 0, 0, 0]       in xrange(4):         if + j < len(a):           key[i] = a[i + j]       pkey = aes_cbc_encrypt_a32(pkey, key)   return pkey   io.open('user_list.txt', 'r') file:     io.open('user_list_enc.txt', 'a') enc_file:         line in file:             email_split, pass_split = line.replace('\n', '').split(":")             password_aes = prepare_key(str_to_a32(pass_split))             uh = stringhash(email_split.lower(), password_aes)             enc_file.write(email_split + ":" + pass_split + ":" + uh + "\n")             print email_split + ":" + pass_split + ":" + uh + "\n"  


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -