Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Program help I am trying to complete a C program that does C R C calculation . I got everyting to work except a

C Program help

I am trying to complete a C program that does C R C calculation . I got everyting to work except a function to display binary difference at each X O R step .

the program compile using two comand line arguments .

here is how the output should look like :

image text in transcribedimage text in transcribedimage text in transcribed

here is my code so far :

#include #include #include int i_temp=0; char* pointer_stop; int val =0; char binary[50000][12]; char binary_string[50000]; int length=0; int error=0; char input[50000]; char lowercase[50000]; char chksm[50000]; char tester[50000]; char string_end[50000]; char *polynomial;

//HEX-BINARY void HEXA_BIN(char *hexaDecimal) { long int i=0; char block[5]; while(hexaDecimal[i]) { switch(hexaDecimal[i]) { case '0': strcpy(block, "0000"); break; case '1': strcpy(block, "0001"); break; case '2': strcpy(block, "0010"); break; case '3': strcpy(block, "0011"); break; case '4': strcpy(block, "0100"); break; case '5': strcpy(block, "0101"); break; case '6': strcpy(block, "0110"); break; case '7': strcpy(block, "0111"); break; case '8': strcpy(block, "1000"); break; case '9': strcpy(block, "1001"); break; case 'a': strcpy(block, "1010"); break; case 'b': strcpy(block, "1011"); break; case 'c': strcpy(block, "1100"); break; case 'd': strcpy(block, "1101"); break; case 'e': strcpy(block, "1110"); break; case 'f': strcpy(block, "1111"); break; } i++; strcat(binary_string, block); } } void CrcChecker() { int i,p; int c; for(i=0; i chksm[i]= binary_string[i]; do { if(chksm[0]=='1') { for(c = 1; c

//BINARY-HEX void BIN_HEXA(char *binary) { long int dec; long int rm; long int qt; int i=1,j,temp; char hx[50000]; dec = strtol (binary,NULL,2); qt = dec; while(qt!=0) { temp = qt % 16; if( temp 0; j--) printf("%c",hx[j]); printf(" (hex)");

}

//MAIN int main(int argc, char *argv[]) { int i=0,e=0; int i_line=0; polynomial="1101"; polynomial="1100110110101"; int spacer=0;

strcpy(input, argv[2]); printf("----------------------------------------------------------------------- ");

//CHOOSE CALC MODE if (strcmp(argv[1], "c") == 0) { printf("The input string (hex): %s ", input);

for(i = 0; i { lowercase[i] = tolower(input[i]); } HEXA_BIN(lowercase); printf("The input string (bin): " );

for(i=0; i { printf("%c" , binary_string[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf(" "); printf(" "); printf("The polynomial that was used (binary bit string): "); for(i=0; i { printf("%c" , polynomial[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf(" "); printf("Mode of operation: calculate "); printf(" "); printf("Number of zeroes that will be appended to the binary input : 12 "); printf(" "); printf("The binary string difference after each XOR step of the CRC calculation: "); length = strlen(binary_string); for(i=strlen(binary_string); i

//CHOOSE VERIFY MODE else if (strcmp(argv[1], "v") == 0) { printf("The input string (hex): %s ", input); for(i = 0; i { lowercase[i] = tolower(input[i]); } HEXA_BIN(lowercase); printf("The input string (bin): " ); for(i=0; i { printf("%c" , binary_string[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf(" "); printf(" "); printf("The polynomial that was used (binary bit string): "); for(i=0; i { printf("%c" , polynomial[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf(" "); printf(" "); printf(" Mode of operation: verification "); printf(" The CRC observed at the end of the input: "); i_line=0; i_temp=0; for(i=strlen(binary_string) - 12; i { printf("%c" , binary_string[i]); string_end[i_temp]=binary_string[i]; i_temp++; i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf("(bin) = "); BIN_HEXA(string_end); printf(" ");

length = strlen(binary_string); for(i=strlen(binary_string) - 12; i { binary_string[i]='0'; } length = strlen(binary_string)-12; CrcChecker(); printf(" ");

printf("The binary string difference after each XOR step of the CRC calculation: "); i_line=0; if (strlen(chksm) % 4 == 0) { printf("The CRC computed for the input : "); for(i=0; i { printf("%c" , chksm[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf("(bin) = "); BIN_HEXA(chksm); printf(" "); } else { i_line=0; printf("The CRC computed for the input : 0"); for(i=0; i { printf("%c" , chksm[i]); i_line++; if(i_line == 4) { i_line = 0; printf(" "); } } printf("(bin) = "); BIN_HEXA(chksm); printf(" "); } printf(" "); if(strcmp(chksm,string_end) == 0) { printf("Did the CRC check pass? (Yes or No): Yes "); } else { printf("Did the CRC check pass? (Yes or No): No "); } } }

CIS3360 Fall 2017 Integrity Checking Using CRC Author: [Your_name or names] The input string (hex): 5AE The input string (bin): 0101 1010 1110 The polynomial used (binary bit string): 1100 1101 1010 1 Mode of operation: calculation Number of zeroes that will be appended to the binary input: 12 The binary string difference after each XOR step of the CRC calculation: 0101 1010 1110 0000 0000 000 0011 1100 0011 0100 0000 0000 0000 1111 0101 11100000 0000 0000 0011 1000 0100 1000 0000 0000 0000 1011 0010 0010 0000 0000 0000 0111 1111 1000 1000 0000 0000 0001 1001 0101 1100 0000 0000 0000 0000 1110 1001 The CRC computed from the input: 0000 1110 1001 (bin) - 0E9 (hex)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago