Open cisen opened 3 years ago
#include "pch.h" #include <iostream>
/ int main() { std::cout << "Hello World!\n"; }/ // #include
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 | | ITU G.704 CRC-12 | x12+x11+x3+x+1 | | 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 + 1(用途:硬件,也称为奇偶校验位) | 0x1 or 0x1 (0x1) CRC-5-CCITT | x5 + x3 + x + 1 (ITU G.704 标准) | 0x15 (0x??) CRC-5-USB | x5 + x2 + 1 (用途:USB 信令包) | 0x25 or 0x14 (0x9) CRC-7 | x7 + x3 + 1 (用途:通信系统) | 0x09 or 0x48 (0x11) CRC-8-ATM | x8 + x2 + x + 1 (用途:ATM HEC) | 0x07 or 0xE0 (0xC1) CRC-8-CCITT | x8 + x7 + x3 + x2 + 1 (用途:1-Wire 总线) | CRC-8-Dallas/Maxim | x8 + x5 + x4 + 1 (用途:1-Wire bus) | 0x31 or 0x8C CRC-8 | x8 + x7 + x6 + x4 + x2 + 1 | 0xEA(0x??) CRC-10 | x10 + x9 + x5 + x4 + x + 1 | 0x233 (0x????) CRC-12 | x12 + x11 + x3 + x2 + x + 1(用途:通信系统) | 0x80F or 0xF01 (0xE03) CRC-16-Fletcher | 参见 Fletcher's checksum | 用于 Adler-32 A & B CRC CRC-16-CCITT | x16 + x12 + x5 + 1 (X25, V.41, Bluetooth, PPP, IrDA) | 0x1021 or 0x8408 (0x0811) CRC-16-IBM | x16 +x15 + x2 + 1 | 0x8005 or 0xA001 (0x4003) CRC-16-BBS | x16 + x15 + x10 + x3 (用途: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 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 | 0x04C11DB7 or 0xEDB88320 (0xDB710641) CRC-32C (Castagnoli) | x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1 | 0x1EDC6F41 or 0x82F63B78 (0x05EC76F1) CRC-64-ISO | x64 + x4 + x3 + x + 1(use: ISO 3309) | 0x000000000000001B or 0xD800000000000000 (0xB000000000000001) CRC-64-ECMA-182 | x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + x35 + x33 + x32+ x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + x10 + x9 + x7 + x4 + x + 1(as described in ECMA-182 p.63) | 0x42F0E1EBA9EA3693 or 0xC96C5795D7870F42 (0x92D8AF2BAF0E1E85) CRC-128 | IEEE-ITU 标准。被 MD5 & SHA-1 取代 | CRC-160 | IEEE-ITU 标准。被 MD5 & SHA-1 取代 | <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> </pre><!--EndFragment-->
/ 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]);
}