none
How to pass from CRC Kermit to CRC Xmodem

    Question

  • Hi, I am trying to créate a CRC Xmodem calculator. I write a number, and the program is supposed to generate the CRC Xmodem 4 character code of that number.

    So far, I managed to calculate the CRC Kermit and the CRC-16, but I am not able to find how to calculate the CRC Xmodem number. Thanks in advance for the help.

    string input_number;
                int input_number_length;
                string stringArray = "";
                string[] str_parsed = new string[4096];
                int[] input_bytes = new int[4096];		
                int stringStart = 0;
                int initial_crc = 0x0000;
                int initial_Coefficient = 0x8408;
                int lessSignificantB, crcByteA, crcByteB;
                
                input_number = textoTrama.Text;
                
                if (input_number.Length % 2 != 0)
                {
                	input_number = input_number + " ";
                }
                
                input_number_length = input_number.Length/2;
                
                //************* Divide the string *************
                
                for (int k = 0; k<input_number_length; k++)
                {
                	stringArray = input_number.Substring(stringStart, 2); 
                	str_parsed[k] = stringArray;							
                	stringStart = stringStart + 2;
                }
    
                //******* Conversion from hex string to int *******
                
                for (int i = 0; i < input_number_length; i++) 
                {
                 input_bytes[i] = Int32.Parse(str_parsed[i],         NumberStyles.HexNumber); //Pasa el array Hex a array Int
                	
                }
                
    			//***************** Algorithm ******************
    			
                for (int i = 0; i < input_number_length; i++)
                {
                	initial_crc = initial_crc ^ input_bytes[i];
                    for (int j = 0; j < 8; j++)
                    {
    	                lessSignificantB = initial_crc & 0x0001;  // Mask of LSB
    	                initial_crc = initial_crc >> 1;
    	                initial_crc = initial_crc & 0x7FFF;
    	                if (lessSignificantB == 1)
    	                {
    	                	initial_crc = initial_crc ^ initial_Coefficient;
    	                }
                    }
    			}
                
                crcByteA = initial_crc & 0x00FF;
                crcByteB = (initial_crc >> 8) & 0x00FF;
    
                miCRC.Text = crcByteA.ToString("X") + crcByteB.ToString("X");

    Tuesday, February 10, 2015 7:46 AM

Answers