資源簡介
crc32及crc32-mpeg算法,主要用查表法實現,本人自己編寫,實測么有問題

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?CRCMethod
{
????class?CRCMethod
????{
????????protected?UInt32[]?Crc32Table;
????????protected?UInt32[]?Crc32_MEPGTable;
????????//生成CRC-32碼表
????????public?void?GetCRC32Table()
????????{
????????????UInt32?Crc;
????????????Crc32Table?=?new?UInt32[256];
????????????int?i?j;
????????????for?(i?=?0;?i?256;?i++)
????????????{
????????????????Crc?=?(UInt32)i;
????????????????for?(j?=?8;?j?>?0;?j--)
????????????????{
????????????????????if?((Crc?&?1)?==?1)
????????????????????{
????????????????????????Crc?=?(Crc?>>?1)?^?0xEDB88320;
????????????????????}
????????????????????else
????????????????????{
????????????????????????Crc?>>=?1;
????????????????????}
????????????????}
????????????????Crc32Table[i]?=?Crc;
????????????????Console.WriteLine(“crc32:“?+i+“:“+String.Format(“{0:X8}“?Crc32Table[i]));
????????????}
????????}
????????//生成CRC-32/MPEG-2碼表
????????public?void?GetCRC32_MPEGTable()
????????{
????????????UInt32?Crc;
????????????Crc32_MEPGTable?=?new?UInt32[256];
????????????int?i?j;
????????????for?(i?=?0;?i?256;?i++)
????????????{
????????????????Crc?=?(UInt32)i<<24;
????????????????for?(j?=?8;?j?>?0;?j--)
????????????????{
????????????????????if?((Crc?&?0x80000000)?!=?0)
????????????????????{
????????????????????????Crc?=?(Crc?<1)?^?0x04c11db7;
????????????????????}
????????????????????else
????????????????????{
????????????????????????Crc?=?Crc?<1;
????????????????????}
????????????????}
????????????????Crc32_MEPGTable[i]?=?Crc;
????????????????Console.WriteLine(“crc32_mepg“?+i+“:“+String.Format(“{0:X8}“?Crc32_MEPGTable[i]));
????????????}
????????}
????????//獲取字符串的CRC-32校驗值
????????public?ulong?GetCRC32Str(string?sInputString)
????????{
????????????//生成碼表
????????????GetCRC32Table();
????????????byte[]?buffer?=?System.Text.Encoding.Default.GetBytes(sInputString);
????????????UInt32?value?=?0xffffffff;
????????????int?len?=?buffer.Length;
????????????for?(int?i?=?0;?i?????????????{
????????????????value?=?(value?>>?8)?^?Crc32Table[(value?&?0xFF)?^?buffer[i]];
????????????}
????????????return?value?^?0xffffffff;
????????}
????????//獲取字符串的CRC-32/MPEG-2校驗值
????????public?ulong?GetCRC32_MPEGStr(string?sInputString)
????????{
???????????//?生成碼表
????????????GetCRC32_MPEGTable();
????????????byte[]?buffer?=?System.Text.Encoding.Default.GetBytes(sInputString);
????????????UInt32?value?=?0xffffffff;
????????????int?len?=?buffer.Length;
????????????for?(int?i?=?0;?i?????????????{
????????????????value?=?(value?<8)?^?Crc32_MEPGTable[(value?>>?24)?^?buffer[i]];
????????????}
????????????return?value;?????????
????????}
????????public?string?StringToHexString(string?s)
????????{
????????????byte[]?b?=?System.Text.Encoding.Default.GetBytes(s);//按照指定編碼將string編程字節數組
????????????string?result?=?string.Empty;
????????????for?(in
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-09-13?16:09??CRCMethod\
?????目錄???????????0??2018-09-14?11:52??CRCMethod\CRCMethod\
?????文件????????3291??2018-09-17?16:52??CRCMethod\CRCMethod\CRCMethod.cs
?????文件????????2479??2018-09-14?13:23??CRCMethod\CRCMethod\CRCMethod.csproj
?????文件?????????532??2018-09-17?16:07??CRCMethod\CRCMethod\Program.cs
?????目錄???????????0??2018-09-13?16:09??CRCMethod\CRCMethod\Properties\
?????文件????????1368??2018-09-13?16:09??CRCMethod\CRCMethod\Properties\AssemblyInfo.cs
?????目錄???????????0??2018-09-14?11:52??CRCMethod\CRCMethod\bin\
?????目錄???????????0??2018-09-13?16:14??CRCMethod\CRCMethod\bin\Debug\
?????文件????????6144??2018-09-17?16:51??CRCMethod\CRCMethod\bin\Debug\CRCMethod.exe
?????文件???????17920??2018-09-17?16:51??CRCMethod\CRCMethod\bin\Debug\CRCMethod.pdb
?????文件???????11600??2018-09-17?16:51??CRCMethod\CRCMethod\bin\Debug\CRCMethod.vshost.exe
?????文件?????????490??2010-03-17?22:39??CRCMethod\CRCMethod\bin\Debug\CRCMethod.vshost.exe.manifest
?????目錄???????????0??2018-09-18?09:24??CRCMethod\CRCMethod\bin\Release\
?????目錄???????????0??2018-09-13?16:09??CRCMethod\CRCMethod\obj\
?????目錄???????????0??2018-09-13?16:09??CRCMethod\CRCMethod\obj\x86\
?????目錄???????????0??2018-09-17?16:51??CRCMethod\CRCMethod\obj\x86\Debug\
?????文件?????????319??2018-09-17?16:51??CRCMethod\CRCMethod\obj\x86\Debug\CRCMethod.csproj.FileListAbsolute.txt
?????文件????????6144??2018-09-17?16:51??CRCMethod\CRCMethod\obj\x86\Debug\CRCMethod.exe
?????文件???????17920??2018-09-17?16:51??CRCMethod\CRCMethod\obj\x86\Debug\CRCMethod.pdb
?????文件????????5833??2018-09-17?16:51??CRCMethod\CRCMethod\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????6016??2018-09-14?09:50??CRCMethod\CRCMethod\obj\x86\Debug\ResolveAssemblyReference.cache
?????目錄???????????0??2018-09-18?09:24??CRCMethod\CRCMethod\obj\x86\Debug\TempPE\
?????文件?????????869??2018-09-13?16:09??CRCMethod\CRCMethod.sln
?????文件???????18432??2018-09-17?17:02??CRCMethod\CRCMethod.suo
- 上一篇:嵌入式MP3播放器項目源代碼
- 下一篇:局域網傳輸文件 聊天工具 飛鴿
評論
共有 條評論