• python 加密方式


    code

    #coding=utf-8
    import os
    import random
    import time
    
    
    def test(book_type,book_id):
        #获取指定长度的随机数字
        #支持16进制数的最大的长度为9
        random_str_length=random.randint(3,6)
        indexlist=range(1,10)  
        indexs=random.sample(indexlist,random_str_length)
        #随机字符串
        random_str=""
        for i in indexs:
            random_str+=str(i)
        #假设book_id 长度<=9
        book_id_length=len(str(book_id))
        timestamp="".join(str(time.time()).split("."))
        out_trade_no = timestamp+str(book_type)+random_str+str(random_str_length)+str(book_id)+str(book_id_length)
    
        return out_trade_no
    
    out_trade_no=test(80,1110)
    print(out_trade_no)
    
    #123123123165123310004
    #解析出book_id,book_type
    book_id_length=int(out_trade_no[-1])
    
    left=0-(book_id_length+1)
    book_id=int(out_trade_no[left:-1])
    print(book_id)
    
    random_str_length=int(out_trade_no[0-(book_id_length+2)])
    
    left=0-(random_str_length+book_id_length+4)
    right=0-(random_str_length+book_id_length+2)
    
    book_type=out_trade_no[left:right]
    
    print(book_type)

  • 相关阅读:
    2.18周四笔记
    Tkinter 控件详细介绍
    python基础: day4作业计算器
    Python的functools.reduce用法
    正则表达式技术深入
    递归
    生成器generator
    绕过验证码
    导入JSONPathExtractorExample.jmx文件报错,导不进去
    jmeter一些插件下载网址
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14181646.html
Copyright © 2020-2023  润新知