cisen / blog

Time waits for no one.
135 stars 20 forks source link

CRC 算法相关 #1038

Open cisen opened 3 years ago

cisen commented 3 years ago

/ int main() { std::cout << "Hello World!\n"; }/ // #include

include

include

define n 7

using namespace std; int main() { system("title = LFSR"); //初始化n位的二进制数据,初始状态为二进制1000000,及十进制8 bitsetbint(64); bitsetstr(bint); string s1, s2;//保存输出结果 //遍历bint中的数字 /for (int i = bint.size()-1; i>=0; i--) cout << bint[i]; cout << endl;/ cout << "初始状态为:" << bint.to_string() << endl; //str = bint.to_string();//如果是string类型的str用这句 //生成LFSR的状态变化 do { // ^两个相同则返回假,1^0 = 1 int j = bint[n - 1] ^ bint[0]; // 右移动1位变成0100000 bint.operator>>=(1);//向右移1位 //第1个数据和第n个数据异或然后赋值给第n个,变成1100000 // bint[6]一直等于前一个bint[6]^bint[0] bint[n - 1] = j; cout << bint.to_string() << endl; //把bint转换成string放入s1 s1 = bint.to_string(); //把a1放入s2中 s2.push_back(s1[3]);

} while (str.to_string() != bint.to_string());
cout << "输出序列为:" << s2 << endl;
system("pause");
return 0;

}



名称 | 生成多项式 | 简记式* | 应用举例
-- | -- | -- | --
CRC-4 | x4+x+1 | &nbsp; | ITU G.704
CRC-12 | x12+x11+x3+x+1 | &nbsp; | &nbsp;
CRC-16 | x16+x12+x2+1 | 1005 | IBM SDLC
CRC-ITU** | x16+x12+x5+1 | 1021 | ISO HDLC, ITU X.25, V.34/V.41/V.42, PPP-FCS
CRC-32 | x32+x26+x23+...+x2+x+1 | 04C11DB7 | ZIP, RAR, IEEE 802 LAN/FDDI, IEEE 1394, PPP-FCS
CRC-32c | x32+x28+x27+...+x8+x6+1 | 1EDC6F41 | SCTP

名称 | 多项式 | 表示法:正常或者翻转
-- | -- | --
CRC-1 | x&nbsp;+ 1(用途:硬件,也称为奇偶校验位) | 0x1 or 0x1 (0x1)
CRC-5-CCITT | x5&nbsp;+&nbsp;x3&nbsp;+&nbsp;x&nbsp;+ 1 (ITU G.704 标准) | 0x15 (0x??)
CRC-5-USB | x5&nbsp;+&nbsp;x2&nbsp;+ 1 (用途:USB 信令包) | 0x25 or 0x14 (0x9)
CRC-7 | x7&nbsp;+&nbsp;x3&nbsp;+ 1 (用途:通信系统) | 0x09 or 0x48 (0x11)
CRC-8-ATM | x8&nbsp;+&nbsp;x2&nbsp;+&nbsp;x&nbsp;+ 1 (用途:ATM HEC) | 0x07 or 0xE0 (0xC1)
CRC-8-CCITT | x8&nbsp;+&nbsp;x7&nbsp;+&nbsp;x3&nbsp;+&nbsp;x2&nbsp;+ 1 (用途:1-Wire 总线) | &nbsp;
CRC-8-Dallas/Maxim | x8&nbsp;+&nbsp;x5&nbsp;+&nbsp;x4&nbsp;+ 1 (用途:1-Wire bus) | 0x31 or 0x8C
CRC-8 | x8&nbsp;+&nbsp;x7&nbsp;+&nbsp;x6&nbsp;+&nbsp;x4&nbsp;+&nbsp;x2&nbsp;+ 1 | 0xEA(0x??)
CRC-10 | x10&nbsp;+ x9&nbsp;+ x5&nbsp;+ x4&nbsp;+ x + 1 | 0x233 (0x????)
CRC-12 | x12&nbsp;+&nbsp;x11&nbsp;+&nbsp;x3&nbsp;+&nbsp;x2&nbsp;+&nbsp;x&nbsp;+ 1(用途:通信系统) | 0x80F or 0xF01 (0xE03)
CRC-16-Fletcher | 参见 Fletcher's checksum | 用于 Adler-32 A &amp; B CRC
CRC-16-CCITT | x16&nbsp;+&nbsp;x12&nbsp;+&nbsp;x5&nbsp;+ 1 (X25, V.41, Bluetooth, PPP, IrDA) | 0x1021 or 0x8408 (0x0811)
CRC-16-IBM | x16&nbsp;+x15&nbsp;+&nbsp;x2&nbsp;+ 1 | 0x8005 or 0xA001 (0x4003)
CRC-16-BBS | x16&nbsp;+ x15&nbsp;+ x10&nbsp;+ x3&nbsp;(用途:XMODEM 协议) | 0x8408 (0x????)
CRC-32-Adler | See Adler-32 | 参见 Adler-32
CRC-32-MPEG2 | See IEEE 802.3 | 参见 IEEE 802.3
CRC-32-IEEE 802.3 | x32&nbsp;+&nbsp;x26&nbsp;+&nbsp;x23&nbsp;+&nbsp;x22&nbsp;+&nbsp;x16&nbsp;+&nbsp;x12&nbsp;+&nbsp;x11&nbsp;+&nbsp;x10&nbsp;+&nbsp;x8&nbsp;+&nbsp;x7&nbsp;+&nbsp;x5&nbsp;+&nbsp;x4&nbsp;+&nbsp;x2&nbsp;+&nbsp;x&nbsp;+ 1 | 0x04C11DB7 or 0xEDB88320 (0xDB710641)
CRC-32C (Castagnoli) | x32&nbsp;+&nbsp;x28&nbsp;+&nbsp;x27&nbsp;+&nbsp;x26&nbsp;+&nbsp;x25&nbsp;+&nbsp;x23&nbsp;+&nbsp;x22&nbsp;+&nbsp;x20&nbsp;+&nbsp;x19&nbsp;+&nbsp;x18&nbsp;+&nbsp;x14&nbsp;+&nbsp;x13&nbsp;+&nbsp;x11&nbsp;+&nbsp;x10&nbsp;+&nbsp;x9&nbsp;+&nbsp;x8&nbsp;+&nbsp;x6&nbsp;+ 1 | 0x1EDC6F41 or 0x82F63B78 (0x05EC76F1)
CRC-64-ISO | x64&nbsp;+&nbsp;x4&nbsp;+&nbsp;x3&nbsp;+&nbsp;x&nbsp;+ 1(use: ISO 3309) | 0x000000000000001B or 0xD800000000000000 (0xB000000000000001)
CRC-64-ECMA-182 | x64&nbsp;+&nbsp;x62&nbsp;+&nbsp;x57&nbsp;+&nbsp;x55&nbsp;+&nbsp;x54&nbsp;+&nbsp;x53&nbsp;+&nbsp;x52&nbsp;+&nbsp;x47&nbsp;+&nbsp;x46&nbsp;+&nbsp;x45&nbsp;+&nbsp;x40&nbsp;+&nbsp;x39&nbsp;+&nbsp;x38&nbsp;+&nbsp;x37&nbsp;+&nbsp;x35&nbsp;+&nbsp;x33&nbsp;+&nbsp;x32+&nbsp;x31&nbsp;+&nbsp;x29&nbsp;+&nbsp;x27&nbsp;+&nbsp;x24&nbsp;+&nbsp;x23&nbsp;+&nbsp;x22&nbsp;+&nbsp;x21&nbsp;+&nbsp;x19&nbsp;+&nbsp;x17&nbsp;+&nbsp;x13&nbsp;+&nbsp;x12&nbsp;+&nbsp;x10&nbsp;+&nbsp;x9&nbsp;+&nbsp;x7&nbsp;+&nbsp;x4&nbsp;+&nbsp;x&nbsp;+ 1(as described in ECMA-182 p.63) | 0x42F0E1EBA9EA3693 or 0xC96C5795D7870F42 (0x92D8AF2BAF0E1E85)
CRC-128 | IEEE-ITU 标准。被 MD5 &amp; SHA-1 取代 | &nbsp;
CRC-160 | IEEE-ITU 标准。被 MD5 &amp; SHA-1 取代 | &nbsp;

<pre style="white-space: normal; color: rgb(70, 70, 70); font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(119, 152, 163); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><br>&nbsp;</pre><!--EndFragment-->