필터 지우기
필터 지우기

how to check whether my CRC32 is calculated correct

조회 수: 36 (최근 30일)
Muhammad nasiri
Muhammad nasiri 2017년 11월 18일
댓글: Walter Roberson 2021년 11월 22일
I take input from user and calculate CRC32 for it, now I have the CRC32 for the input string, how to check if it is correct, in other words, how to decode back from CRC, any code will be appreciated
HERE is my code:
prompt = 'Please Enter your message \n';
Data = input(prompt,'s'); %Taking input from the user
crc = uint32(hex2dec('FFFFFFFF')); %Initalize CRC with all 32 bits (1's)
poly = uint32(hex2dec('EDB88320')); %Standard Polynomial of CRC32 in hex converted to decimals then to unsigned int32
data = uint8(Data); %Every char of input data is considered as one byte = 8 bits, and is converted to unisigned int8
% **** Computing CRC-32 value ****
for i = 1:length(data)
crc = bitxor(crc,uint32(data(i))); % type casting data to unisigned int32 inorder to be same as crc initial value type, then performing bitwise xor operations.
for j = 1:8 % Computing CRC on byte by byte basis (as required)
mask = bitcmp(bitand(crc,uint32(1))); %After performing bit wise AND operation, we take bit complement which is nothing but itself subtracted from the maximum integer of its data type
if mask == intmax('uint32'), mask = 0; %If value of mask even after taking complement is equal to maximum number of unit32 data type, we take its value as zero
else mask = mask+1;
end
crc = bitxor(bitshift(crc,-1),bitand(poly,mask));
end
end
crc_in_dec = bitcmp(crc);
crc = dec2bin(crc);
Looking forward to your answers
  댓글 수: 2
Kamal
Kamal 2021년 11월 22일
Interesting how you add 4 lines around the top and bottom and now it becomes your code. This is taken from Costas Vlachos' 2014 post. Why not just use his function?
Walter Roberson
Walter Roberson 2021년 11월 22일
Could you link to that 2014 post by Costas Vlachos ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 18일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by