杭州电子科技大学实验报告学生姓名:韩民杨学号:指导教师:吴端坡实验地点:1#108 实验时间:2015-4-24一、实验室名称:1#108二、实验项目名称:计算机网络实验1Coding on error dectecting algorithms(C++)三、实验学时:四、实验原理:C++编程五、实验目的:利用C++编程CRC16校验及奇偶校验六、实验内容:Coding on error dectecting algorithms(C++)1.Cyclic redundancy checkUsing the polynomials below to encode random generated data stream (40-100bits). Show the FEC, and encoded data frame.CRC-4x4+x+1ITUCRC-16x16+x15+x2+1IBM SDLCCRC-32x32+x26+x23+...+x2+x+1ZIP, RAR, IEEE 802 LAN/FDDI, IEEE 1394,PPP-FCSFor the error patter listed below, what the conclusion does the receiver get Can the receiver find the errorsCase Error patternNo error0000 (0000)One error1000 (000)Two errors100 (001)Random errors Random error pattern2.Parity checkUsing even or odd parity check on random generated data stream (8-20bits).Show encoded data frame.For the error patter listed below, what the conclusion does the receiver get Can the receiver find the errorsCase Error patternNo error0000 (0000)One error1000 (000)Two errors100 (001)七、实验器材(设备、元器件):PC机一台,装有C++集成开发环境。
八、实验步骤:#include<>#include<>#include<>#include<>#include<>#include<>#define NO_ERROR 1#define ONE_ERROR 2#define TWO_ERROR 3#define RANDOM_ERROR 4#define RESULT 1#define CRC 0#define Parity 0#define check 1int flag_parity;000Two errors 100 (001)Random errors Random error pattern*/if(channel_way == NO_ERROR){char *result = NULL;int flagg=0;printf("信道中传输数据:");for(int f =0;f<length*8+len_d-1 ;f++)printf("%c",message_input[f]);printf("\n");printf("正在检错中.......\n");printf("检错结果:");fflush(stdin);result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(int i = 0;i < len_d-1;i++){printf("%c",*result);if((*result) - 48 != 0){printf("\n error! \n");flagg =1;break;}result+=1;}if(flagg == 0)printf("\n no error! \n");}if(channel_way == ONE_ERROR){char *result = NULL;message_input[0] = ((message_input[0] - 48)^('1'-48)) + 48;printf("信道中传输数据:");for(int f =0;f<length*8+len_d-1 ;f++)printf("%c",message_input[f]);printf("\n");printf("正在检错中.......");printf("检错结果:");result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d);for(int i = 0;i < len_d-1;i++){if(*result == '1'){printf("data error! \n");break;}else{continue;result+=1;}}}if(channel_way == TWO_ERROR){char *result = NULL;message_input[0] = ((message_input[0] - 48)^('1'-48)) + 48;message_input[length*8-1] = ((message_input[length*8-1] - 48)^('1'-48)) + 48;printf("信道中传输数据:");for(int f =0;f<length*8+len_d-1 ;f++)printf("%c",message_input[f]);printf("\n");printf("正在检错中.......");printf("检错结果:");result = crc_function(message_input,len,dividend,len_d,RESULT,crc);for(int i = 0;i < len_d-1;i++){if(*result != '0'){ printf(" data error! \n");break;}else{ continue;result+=1;}}}if(channel_way == RANDOM_ERROR){char *result = NULL;int no;srand( (unsigned)time( NULL ) ); .....\n");printf("检错结果:");result = crc_function(message_input,len,dividend,len_d,RESULT,crc);for(int i = 0;i < len_d-1;i++){if(*result != '0'){printf(" data error! \n");break;}else{continue;result+=1;}}}printf("************************************\n");printf("\n");printf("\n");}else{printf("Please select the parity mode\n");printf(" parity \n");printf(" parity\n");scanf("%d",&flag_parity);char m = Parity_check(message_input,length*8,Parity);printf("在信道中传输的message:");message_input[length*8] = m ;for(int message_number = 0;message_number<=length*8;message_number++)printf("%c",message_input[message_number]);printf("\n");printf("*************************************\n");printf("****** analog channel ******\n");printf("***please choice the way of error****\n");printf("**** error *****\n");printf("**** error *****\n");printf("**** errors *****\n");scanf("%d",&channel_way);if(channel_way == NO_ERROR){for(int f =0;f<length*8;f++)printf("%c",message_input[f]);printf("正在检错中.......\n");printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);if(flag_parity_mode == (message_input[length*8]))printf("no error!\n");}if(channel_way == ONE_ERROR){message_input[0] = ((message_input[0] - 48)^('1'-48)) + 48;for(int f =0;f<length*8;f++)printf("%c",message_input[f]);printf("正在检错中.......\n");printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);printf(" error!\n");}if(channel_way == TWO_ERROR){message_input[0] = ((message_input[0] - 48)^('1'-48)) + 48;message_input[length*8-1] = ((message_input[length*8-1] - 48)^('1'-48)) + 48;for(int f =0;f<length*8;f++)printf("%c",message_input[f]);printf("正在检错中.......\n");printf("检错结果:");char flag_parity_mode = Parity_check(message_input,length*8,check);printf("no error!\n");}printf("************************************\n");printf("\n");printf("\n");}fflush(stdin);printf("do you want to continuey/n\n");scanf("%c",&flag);if(flag == 'y')continue;elsebreak;}}/*********************************************** /function:完成字节转换成位的功能/输入字符:In 输出的二进制:Out************************************************/ void ByteToBit(char* out,const char* in,int bits){中'0'=48for(j=0;j<len;j++){/*把1传入48表示为"0";*/if(*input_p==48){入界面2.输入数据3.CRC校验1)No error2)One error3)Two errors4)Random errors4.奇偶校验①界面②Even parity 1)No error2)One error3)Two errors③Odd parity1)No error2)One error3)Two errors十、实验结论:奇偶校验,1位错可发现,2位错不可发现(奇数个错可发现,偶数个错不可发现)。