pad and unpad byte array,padunpad,Demonstrates
pad and unpad byte array,padunpad,Demonstrates
Demonstrates using the pad and unpad methods of CkByteArray.
import chilkatdata = chilkat.CkByteData()data.append(\'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\',10)# These are the padding options for the \"pad\" method:# 0 = Each padding byte is the pad count (16 extra added if size is already a multiple of 16)# 1 = Random bytes except the last is the pad count (16 extra added if size is already multiple of 16)# 2 = Pad with random data. (If already a multiple of 16, no padding is added).# 3 = Pad with NULLs. (If already a multiple of 16, no padding is added).# 4 = Pad with SPACE chars(0x20). (If already a multiple of 16, no padding is added).# We\'ll pad to a block size of 16 bytes.blockSize = 16paddingScheme = 0# Pad, display the padded byte data, unpad, then re-displaydata.pad(blockSize,paddingScheme)print data.getEncoded(\"hex\")data.unpad(16,paddingScheme)print data.getEncoded(\"hex\")print \"----\"paddingScheme = 1# Pad, display the padded byte data, unpad, then re-displaydata.pad(blockSize,paddingScheme)print data.getEncoded(\"hex\")data.unpad(16,paddingScheme)print data.getEncoded(\"hex\")print \"----\"# There is no unpadding with schemes 2,3, and 4data2 = chilkat.CkByteData()data2.append(\'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\',10)paddingScheme = 2# Pad and display the padded byte datadata2.pad(blockSize,paddingScheme)print data2.getEncoded(\"hex\")print \"----\"# There is no unpadding with schemes 2,3, and 4data3 = chilkat.CkByteData()data3.append(\'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\',10)paddingScheme = 3# Pad and display the padded byte datadata3.pad(blockSize,paddingScheme)print data3.getEncoded(\"hex\")print \"----\"# There is no unpadding with schemes 2,3, and 4data4 = chilkat.CkByteData()data4.append(\'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\',10)paddingScheme = 4# Pad and display the padded byte datadata4.pad(blockSize,paddingScheme)print data4.getEncoded(\"hex\")print \"----\"#该片段来自于http://byrx.net
相关内容
- 通过urllib实现的gohper客户端代码,urllibgohper客户端,im
- 用python实现的抓取腾讯视频所有电影的爬虫,python爬虫
- python性能测试脚本,python性能测试,下面是我写的一个性
- 抓取煎蛋(jandan.net)上的无聊图或妹子图的url并保存文件
- python实现的一个抽象图像类,python实现图像,#!/usr/bin/
- python中base64加密解密方法,pythonbase64,一 base64Base
- python 判断文件MIME,python判断mime,MIME TYPE 键值
- 插入排序,,#插入排序def ins
- 下载豆瓣音乐小站歌曲,豆瓣小站歌曲,代码已经放到
- 用python计算(1+2+3+4……+100),python,n=0for x in
评论关闭