# encoding: utf-8
import xlrd
import os
import yaml
import logging.config
from Crypto.Cipher import AES
import base64 def setup_logging(default_path = "log_config.yaml",default_level = logging.INFO,env_key = "LOG_CFG"):
path = default_path
value = os.getenv(env_key,None)
if value:
path = value
if os.path.exists(path):
with open(path,"r") as f:
config = yaml.load(f)
logging.config.dictConfig(config)
else:
logging.basicConfig(level = default_level) def encrypt(text, key, iv):
if type(text) is str:
text = text.encode(encoding='utf-8', errors='strict')
if type(key) is str:
key = key.encode(encoding='utf-8', errors='strict')
if type(iv) is str:
iv = iv.encode(encoding='utf-8', errors='strict')
if len(text) % 16:
text += (chr(16 - len(text) % 16) * (16 - len(text) % 16)).encode(encoding='utf-8', errors='strict')
text = base64.b64encode(s=AES.new(key, mode=AES.MODE_CBC, IV=iv).encrypt(text),
altchars=None).decode(encoding='utf-8', errors='strict')
return text def decrypt(cipher_text, key, iv):
if type(key) is str:
key = key.encode(encoding='utf-8', errors='strict')
if type(iv) is str:
iv = iv.encode(encoding='utf-8', errors='strict')
if type(cipher_text) is str:
cipher_text_bytes = base64.b64decode(cipher_text)
#todo aes解密
plaintext_bytes = AES.new(key, mode=AES.MODE_CBC, IV=iv).decrypt(cipher_text_bytes)
#todo 去填充字节
for i in range(1,17):
plaintext_bytes = plaintext_bytes.rstrip(chr(i).encode(encoding='utf-8', errors='strict'))
plaintext = plaintext_bytes.decode(encoding='utf-8', errors='strict')
return plaintext if __name__ == '__main__':
setup_logging()
"""
book = xlrd.open_workbook('testdata_1.xlsx')
sheet = book.sheet_by_index(0) # 根据顺序获取sheet
print(sheet.ncols) # 获取excel里面有多少列
print(sheet.nrows) # 获取excel里面有多少行
for i in range(1, sheet.nrows):
user_info_dict = {}
if len(sheet.cell(i, 0).value) > 0:
user_info_dict['name'] = sheet.cell(i, 0).value.strip()
user_info_dict['idcard'] = sheet.cell(i, 1).value.strip()
print(sheet.cell(i, 2).value)
print(sheet.cell(i, 2).ctype)
user_info_dict['phone'] = str(int(sheet.cell(i, 2).value)).strip()
print(user_info_dict)
print(chr(1))
""" for i in range(1,20):
s = 'a'* i
logging.info(('s', s))
mw = encrypt(s,'', '')
logging.info(('e',mw))
logging.info(('d',decrypt(mw,'', '')))
logging.info('====================')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'a')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'iEqJ43muMK0K98y26ZG55A==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'a')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'tXevZVzEJABPQtw9DECgYQ==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', '/I7IfuZDcDaKXZtifDcs5w==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'Alk1FhjAr4JUbb+m+u+F2Q==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'udmP3Tf0/u4RYBMKJPJ0/A==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'PdwwbsFTMHDNUsJMZAeM+A==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'X5sjPFnk30mCHVDVacXjyA==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'n67DCEhkX6Dr0soQVz63zg==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 72 - ('e', 'jmv9NFzbmiWcpd+gOMXFLg==')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaa')
2018-10-31 08:59:50,153 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,153 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'N1eeE8sahDhoNxGKhHINcg==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'X5ldc5VOXhEY9mpySsAf8A==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'S2z8gQ/EzVhbhcthz1ILbQ==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'FMNUDHyJxF13BvqT3Iru6g==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'hB6U1AchwgQuYOlwMcmegA==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'N7wIcnTQH5jlRyG6YqAcqA==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'LWlQdN/UTy+opSdVdh/hyw==')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'LWlQdN/UTy+opSdVdh/hyw4zq/Ogqcr8FyuqK/GUqAY=')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'LWlQdN/UTy+opSdVdh/hy1q9voPP4CUk7ON/d/piMPU=')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ====================
2018-10-31 08:59:50,169 - root - INFO - MainThread - 70 - ('s', 'aaaaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 72 - ('e', 'LWlQdN/UTy+opSdVdh/hy736EUVnpijwTpyfWWP+i0k=')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 73 - ('d', 'aaaaaaaaaaaaaaaaaaa')
2018-10-31 08:59:50,169 - root - INFO - MainThread - 74 - ==================== Process finished with exit code 0

最新文章

  1. JavaScript进阶之路——认识和使用Promise,重构你的Js代码
  2. Jquery UI
  3. Code First 迁移,及迁移错误
  4. phpstorm 激活服务器
  5. myeclipse6.5注册机
  6. ASP.NET连接数据库时,提示“用户 'sa' 登录失败原因: 未与信任 SQL Server 连接相关联
  7. Oracle SQL Tips
  8. CentoS 下安装gitlab
  9. SQL 表值函数
  10. (三)Qt语言国际化
  11. linux下ssh使用rsa验证登陆MACOX
  12. (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)
  13. 交互模式下测试python代码及变量的四则运算
  14. TableML Excel编译/解析工具
  15. 目标检测之R-CNN系列
  16. 洛谷P2756 飞行员配对方案问题
  17. 内存管理 re模块
  18. Netty实战九之单元测试
  19. Android测试(一):在Android中测试App
  20. PowerDesigner最基础的使用方法入门学习(二)

热门文章

  1. 自定义django-admin命令
  2. linq之左连接 + group by
  3. Linux各目录及每个目录的详细介绍
  4. 洛谷P3258 松鼠的新家
  5. Matplotlib学习---用matplotlib和sklearn画拟合线(line of best fit)
  6. ALGO-19 审美课
  7. 【XSY2760】nonintersect 计算几何
  8. 【XSY2680】玩具谜题 NTT 牛顿迭代
  9. Odoo
  10. TP5调用微信JSSDK 教程 - 测试成功案例