Home > Backend Development > PHP Tutorial > python实现了字符串的按位异或和php中的strpad函数

python实现了字符串的按位异或和php中的strpad函数

WBOY
Release: 2016-06-23 13:33:23
Original
1202 people have browsed it

最近在写自动化测试,由于开发加密中用到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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template