一、原理及每步实现见文章:https://juejin.cn/post/7084242293816983589?searchId=20240321135336F4E57A424C6F2E776B59二、代码(1)来源此文章的最完整代码:# __author: Junebao # data:2020/3/9 from bitarray import bitarray class MyDES: def __init__(self): self.child_keys = [] @staticmethod def _bit_encode(s: str) -> str: """ 将字符串转换为01字符串的形式 """ return bitarray( ''.join([bin(int('1' + hex(c)[2:], 16))[3:]
原理一、基本原理 CRC检验原理实际上就是在一个p位二进制数据序列之后附加一个r位二进制检验码(序列),从而构成一个总长为n=p+r位的二进制序列;附加在数据序列之后的这个检验码与数据序列的内容之间存在着某种特定的关系。如果因干扰等原因使数据序列中的某一位或某些位发生错误,这种特定关系就会被破坏。因此,通过检查这一关系,就可以实现对数据正确性的检验。二、几个基本概念1、帧检验序列FCS(Frame Check Sequence):为了进行差错检验而添加的冗余码。2、多项式模2运行:实际上是按位异或(Exclusive OR)运算,即相同为0,相异为1,也就是不考虑进位、借位的二进制加减运算。如:10011011 + 11001010 = 01010001。3、生成多项式(generator polynomial):当进行CRC检验时,发送方与接收方需要事先约定一个除数,即生成多项式,一般记作G(x)。生成多项式的最高位与最低位必须是1。常用的CRC码的生成多项式有:CRC8=X8+X5+X4+1CRC-CCITT=X16+X12+X5+1CRC16=X16+X15+X5+1CRC1
一、原理见文章https://www.cnblogs.com/luop/p/4334160.html二、python实现以下文章从参数类型、加密模式、编码模式、补全模式、等等方面 系统的说明如何使用AES加密解密。https://www.cnblogs.com/Hellowshuo/p/15706590.html代码如下:from Crypto.Cipher import AES import base64 import binascii # 数据类 class MData(): def __init__(self, data = b"",characterSet='utf-8'): # data肯定为bytes self.data = data self.characterSet = characterSet def saveData(self,FileName): with open(FileName,'wb') as f: f.write(self.
base家族编码包含多种编码方式,每种都有不同的特点,本篇文章从初学的角度学习一下base家族编码。base家族编码是较为基础的加密算法,需要掌握;一、base16编码base16编码也称为十六进制编码或Hex编码,是一种将二进制数据表示为十六进制数字和字符的方法。它使用16个字符(0-9和A-F)来表示4位二进制数的每个组合。(1)编码原理:由于4bit就可以表示2^4 = 16个字符。所以用4bit可以表示所有的十六进制数。1byte=8bit 所以1byte = 俩个十六进制数据。这里就涉及一个字节序的问题:是用大端模式还是小端模式?Base16编码明确表明是用小端模式存储。(2)编码过程:1.将二进制数据分割为4个一组2.映射,将每四位二进制数据映射到对应的base16字符。如下:0000 -> 0 0001 -> 1 0010 -> 2 0011 -> 3 0100 -> 4 0101 -> 5 0110 -> 6 0111 -> 7 1000 -> 8 1001 -> 9 1010 -> A 1011 -&g
base64一、什么是Base64Base64是一种基于64个可打印字符来表示二进制数据的表示方法。由于2^6=64,所以每6个比特为一个单元,对应某个可打印字符。3个字节有24个比特,对应于4个Base64单元,即3个字节可由4个可打印字符来表示。在Base64中的可打印字符包括字母A-Z、a-z、数字0-9,这样共有62个字符,此外两个可打印符号在不同的系统中而不同。二、python中的base64模块base64模块实际上调用的是binascii模块Base64模块真正用得上的方法只有8个,分别是:encode, decode为一组, 专门用来编码和解码文件的, 也可以对StringIO里的数据做编解码;encodestring, decodestring为一组,专门用来编码和解码字符串b64encode, b64decode为一组, 用来编码和解码字符串,并且有一个替换符号字符的功能因为Base64编码后的字符除了英文字母和数字外还有三个字符’ + / =‘,其中’=‘只是为了补全编码后的字符数为4的整数,而’+‘和’/‘在一些情况下需要被替换的,b64encode和b64de
Norman1z