zoukankan      html  css  js  c++  java
  • python实现了字符串的按位异或和php中的strpad函数

    近期在写自己主动化測试,因为开发加密中用到strpad和字符串的按位异或,而python中没有这种函数和功能,所以必须自己写一套,要不自己主动化測试无法进行,所以就用python实现了一下,因为在写字符串的按位异或中遇到非常多坑。并且网上资料特别少,所以把这个分享一下:

    #php的strpad
    def leftPadZero(ori,len,targetLen):
        if(len>=targetLen):
            return ori
        paddingLen = targetLen - len
        rst="0"*paddingLen+ori
        return  rst




    #字符串的异或操作
    #ord 和chr 新函数的学习 将字符和ASCII相互转换
    def stringxor(str1,str2):
        orxstr=""
        for i in range(0,len(str1)-1):
            rst=ord(list(str1)[i])^ord(list(str2)[i])
            orxstr=orxstr+ chr(rst)
        return orxstr


  • 相关阅读:
    leetcode144 longest-palindromic-substring
    数据结构之二叉树
    数据结构之堆
    数据结构之图
    数据结构之排序
    数据结构之动态规划
    14 RPC
    数据结构之字符串
    数据结构之散列表
    16 中间人攻击
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5078501.html
Copyright © 2011-2022 走看看