⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 矛与盾的较量(2)——crc原理篇.htm

📁 CRC16的源程序
💻 HTM
📖 第 1 页 / 共 4 页
字号:
                        name=L138><FONT 
                        color=#238e23>;**************************************************************</FONT><BR><A 
                        name=L139>arraycrc32&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>proc</FONT><BR><A name=L140><BR><A 
                        name=L141>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;计算 CRC-32 
                        ,我采用的是把整个字符串当作一个数组,然后把这个数组的首地址赋值给 EBX,把数组的长度赋值给 
                        ECX,然后循环计算,返回值(计算出来的 CRC-32 值)储存在 EAX 中:</FONT><BR><A 
                        name=L142>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;</FONT><BR><A 
                        name=L143>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>; 参数:</FONT><BR><A 
                        name=L144>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EBX 
                        = address of first byte</FONT><BR><A 
                        name=L145>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>; 返回值:</FONT><BR><A 
                        name=L146>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EAX 
                        = CRC-32 of the entire array</FONT><BR><A 
                        name=L147>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EBX 
                        = ?</FONT><BR><A 
                        name=L148>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ECX 
                        = 0</FONT><BR><A 
                        name=L149>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EDX 
                        = ?</FONT><BR><A name=L150><BR><A 
                        name=L151>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>mov</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>eax</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#3080ca>-</FONT><FONT color=#802000>1</FONT> <FONT 
                        color=#238e23>; 先初始化eax</FONT><BR><A 
                        name=L152>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>or</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>ebx</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#ff0000>ebx</FONT><BR><A 
                        name=L153>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>jz</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#802000>$Done</FONT>&nbsp;&nbsp; <FONT 
                        color=#238e23>; 避免出现空指针</FONT><BR><A name=L154>@@<FONT 
                        color=#3080ca>:</FONT><BR><A 
                        name=L155>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>mov</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>dl</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#871f78>[</FONT><FONT 
                        color=#ff0000>ebx</FONT><FONT 
                        color=#871f78>]</FONT><BR><A 
                        name=L156>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>or</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>dl</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#ff0000>dl</FONT><BR><A 
                        name=L157>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>je</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#802000>$Done</FONT>&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;判断是否对字符串扫描完毕</FONT><BR><A 
                        name=L158>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><A 
                        name=L159>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;这里我用查表法来计算 CRC-32 ,因此非常快速:</FONT><BR><A 
                        name=L160>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;因为这是assembly代码,所以不需要给这个过程传递参数,只需要把oldcrc赋值给EAX,以及把byte赋值给DL:</FONT><BR><A 
                        name=L161>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;</FONT><BR><A 
                        name=L162>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>; 在C语言中的形式:</FONT><BR><A 
                        name=L163>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;</FONT><BR><A 
                        name=L164>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp; temp = (oldcrc ^ abyte) 
                        &amp; 0x000000FF;</FONT><BR><A 
                        name=L165>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp; crc&nbsp;&nbsp;= (( oldcrc 
                        &gt;&gt; 8) &amp; 0x00FFFFFF) ^ 
                        crc32tbl[temp];</FONT><BR><A 
                        name=L166>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;</FONT><BR><A 
                        name=L167>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>; 参数:</FONT><BR><A 
                        name=L168>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EAX 
                        = old CRC-32</FONT><BR><A 
                        name=L169>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DL 
                        = a byte</FONT><BR><A 
                        name=L170>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>; 返回值:</FONT><BR><A 
                        name=L171>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EAX 
                        = new CRC-32</FONT><BR><A 
                        name=L172>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#238e23>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EDX 
                        = ?</FONT><BR><A 
                        name=L173>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                        <BR><A 
                        name=L174>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>xor</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>dl</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#ff0000>al</FONT><BR><A 
                        name=L175>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>movzx</FONT>&nbsp;&nbsp; <FONT 
                        color=#ff0000>edx</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#ff0000>dl</FONT><BR><A 
                        name=L176>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>shr</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>eax</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#802000>8</FONT><BR><A 
                        name=L177>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>xor</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>eax</FONT><FONT 
                        color=#9932cd><B>,</B></FONT> <FONT 
                        color=#871f78>[</FONT>crc32tbl<FONT 
                        color=#3080ca>+</FONT><FONT 
                        color=#ff0000>edx</FONT><FONT 
                        color=#3080ca>*</FONT><FONT color=#802000>4</FONT><FONT 
                        color=#871f78>]</FONT><BR><A 
                        name=L178>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><A 
                        name=L179>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>inc</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>ebx</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><A 
                        name=L180>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>jmp</FONT>&nbsp;&nbsp;&nbsp;&nbsp; 
                        @B<BR><A name=L181><BR><A name=L182><FONT 
                        color=#802000>$Done</FONT><FONT 
                        color=#3080ca>:</FONT><BR><A 
                        name=L183>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>not</FONT>&nbsp;&nbsp;&nbsp;&nbsp; <FONT 
                        color=#ff0000>eax</FONT><BR><A 
                        name=L184>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>ret</FONT><BR><A 
                        name=L185>arraycrc32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT 
                        color=#ff0000>endp</FONT><BR><A name=L186><BR><A 
                        name=L187><FONT color=#ff0000>end</FONT> main<BR><A 
                        name=L188><FONT 
                        color=#238e23>;********************&nbsp;&nbsp;&nbsp;&nbsp;over&nbsp;&nbsp;&nbsp;&nbsp;********************</FONT><BR><A 
                        name=L189><FONT color=#238e23>;by 
                    LC</FONT></A></TD></TR></TBODY></TABLE><BR><BR>下面是它的资源文件:<BR><BR>
                  <TABLE bgColor=#fbedbb border=0 cellPadding=0 cellSpacing=0>
                    <TBODY>
                    <TR>
                      <TD><B><BR>#include "resource.h"<BR><BR>#define 
                        IDC_BUTTON_OPEN&nbsp;&nbsp;&nbsp;&nbsp;3000<BR>#define 
                        IDC_EDIT_INPUT 3001<BR>#define IDC_STATIC 
                        -1<BR><BR>LC_DIALOG DIALOGEX 10, 10, 195, 60<BR>STYLE 
                        DS_SETFONT | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | 
                        WS_CAPTION | 
                        <BR>&nbsp;&nbsp;&nbsp;&nbsp;WS_SYSMENU<BR>CAPTION "lc’s 
                        assembly framework"<BR>FONT 9, "宋体", 0, 0, 
                        0x0<BR>BEGIN<BR>&nbsp;&nbsp;&nbsp;&nbsp;LTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                        "请输入一个字符串(区分大小写):",IDC_STATIC,11,7,130,10<BR>&nbsp;&nbsp;&nbsp;&nbsp;EDITTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDC_EDIT_INPUT,11,20,173,12,ES_AUTOHSCROLL<BR>&nbsp;&nbsp;&nbsp;&nbsp;DEFPUSHBUTTON&nbsp;&nbsp; 
                        "Ca&amp;lc",IDC_BUTTON_OPEN,71,39,52,15<BR>END</B></TD></TR></TBODY></TABLE><BR><BR>如果你能够完全理解本节的内容,那么请留意我的下一讲,我将具体介绍如何运用CRC-32对你的文件进行保护。(呵呵,好戏在后头……) 
                </TD></TR>
              <TR>
                <TD>&nbsp;</TD></TR>
              <TR>
                <TD align=right>老罗<BR>2002-8-26 </TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD colSpan=2>&nbsp;</TD></TR>
        <TR>
          <TD colSpan=2>
            <DIV align=center>[<A 
            href="http://www.luocong.com/articles/index.asp">返回</A>]</DIV></TD></TR>
        <TR>
          <TD colSpan=2>&nbsp;</TD></TR>
        <TR>
          <TD colSpan=2>
            <DIV align=center><FONT 
          color=#0066ff>&copy;版权所有&nbsp;老罗的缤纷天地</FONT></DIV></TD></TR>
        <TR>
          <TD colSpan=2>
            <DIV align=center><FONT 
            color=#0066ff>&nbsp;1980-2003&nbsp;欢迎转载&nbsp;转载请注明出处</FONT></DIV></TD></TR></TBODY></TABLE></TD>
    <TD width="2%">&nbsp;</TD></TR>
  <TR>
    <TD height=15 width="3%"><IMG height=30 
      src="矛与盾的较量(2)——CRC原理篇.files/jiao_left_bottom.jpg" width=29></TD>
    <TD height=15 width="95%">&nbsp;</TD>
    <TD align=right height=15 vAlign=bottom width="2%"><IMG height=29 
      src="矛与盾的较量(2)——CRC原理篇.files/jiao_right_bottom.jpg" 
width=30></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -