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

📄 注册码算法问题~!!.htm

📁 注册码算法问题~!!.
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            &nbsp;'髡夔ㄩ蔚坋輛秶杅趼 &nbsp;oData &nbsp;蛌遙峈匐輛秶杅趼 &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Dim &nbsp;k &nbsp;As &nbsp;Integer &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Dim &nbsp;oData &nbsp;As &nbsp;Long 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;oData &nbsp;= &nbsp;SerialNumber &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Do &nbsp;While 
            &nbsp;oData &nbsp;&gt;= &nbsp;8 &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;k &nbsp;= &nbsp;oData &nbsp;Mod 
            &nbsp;8 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;GetSerial &nbsp;= &nbsp;k &nbsp;&amp; &nbsp;GetSerial 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;oData &nbsp;= &nbsp;oData &nbsp;\ &nbsp;8 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Loop &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;If 
            &nbsp;oData &nbsp;&gt; &nbsp;0 &nbsp;Then &nbsp;GetSerial &nbsp;= 
            &nbsp;oData &nbsp;&amp; &nbsp;GetSerial &nbsp;<BR>End &nbsp;Function 
            &nbsp;<BR>&nbsp;<BR>Private &nbsp;Function &nbsp;CheckRegKey(vData 
            &nbsp;As &nbsp;String) &nbsp;As &nbsp;Boolean &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;'髡夔ㄩ潰桄怀&amp;#63541;腔蛁聊鎢岆瘁淏&amp;#63489;ㄛTrue 
            &nbsp;=&gt; &nbsp;淏&amp;#63489;ㄛFalse &nbsp;=&gt; &nbsp;囮啖 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;'&amp;#63220;笢 &nbsp;vData 
            &nbsp;峈蛁聊鎢 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;If &nbsp;UCase(BreakRegKey(vData)) &nbsp;= 
            &nbsp;UCase(Hex(SerialNumber)) &nbsp;Then &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CheckRegKey &nbsp;= 
            &nbsp;True &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Else 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;CheckRegKey &nbsp;= &nbsp;False &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;End &nbsp;If &nbsp;<BR>Quit_Check: &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Exit &nbsp;Function &nbsp;<BR>End &nbsp;Function 
            &nbsp;<BR>&nbsp;<BR>Private &nbsp;Function &nbsp;SerialNumber() 
            &nbsp;As &nbsp;Long &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;'髡夔ㄩ跦擂茞攫煦&amp;#63397;陓洘鳳腕蛁聊陓洘(翋猁岆?煦&amp;#63397;) 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Dim &nbsp;lpVolumeNameBuffer 
            &nbsp;As &nbsp;String &nbsp;* &nbsp;128 &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Dim &nbsp;lpVolumeSerialNumber &nbsp;As &nbsp;Long 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Dim 
            &nbsp;lpMaximumComponentLength &nbsp;As &nbsp;Long &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Dim &nbsp;lpFileSystemFlags &nbsp;As &nbsp;Long 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Dim 
            &nbsp;lpFileSystemNameBuffer &nbsp;As &nbsp;String &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;Dim &nbsp;nFileSystemNameSize &nbsp;As 
            &nbsp;Long &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;GetVolumeInformation &nbsp;"C:\", 
            &nbsp;lpVolumeNameBuffer, &nbsp;Len(lpVolumeNameBuffer), 
            &nbsp;lpVolumeSerialNumber, &nbsp;_ &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;lpMaximumComponentLength, 
            &nbsp;lpFileSystemFlags, &nbsp;lpFileSystemNameBuffer, &nbsp;_ 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;nFileSystemNameSize &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;SerialNumber &nbsp;= 
            &nbsp;lpVolumeSerialNumber &nbsp;<BR>End &nbsp;Function 
            &nbsp;<BR>&nbsp;<BR>Private &nbsp;Function &nbsp;BreakRegKey(mstrKey 
            &nbsp;As &nbsp;String) &nbsp;As &nbsp;String &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;'髡夔ㄩ湖汃蛁聊鎢ㄛ遜埻峈茞攫煦&amp;#63397;?腔橙梓 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;'mstrKey &nbsp;峈蛁聊鎢 &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Dim &nbsp;sKey &nbsp;As &nbsp;String, &nbsp;iKey 
            &nbsp;As &nbsp;Double &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Dim 
            &nbsp;lKey &nbsp;As &nbsp;Integer, &nbsp;iLoop &nbsp;As 
            &nbsp;Integer &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;'&amp;#63471;裁熬瘍 &nbsp;"-" &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;While &nbsp;InStr(1, &nbsp;mstrKey, &nbsp;"-") 
            &nbsp;&gt; &nbsp;0 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;lKey &nbsp;= &nbsp;InStr(1, &nbsp;mstrKey, 
            &nbsp;"-") &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;mstrKey &nbsp;= &nbsp;Left(mstrKey, &nbsp;lKey &nbsp;- 
            &nbsp;1) &nbsp;&amp; &nbsp;Right(mstrKey, &nbsp;Len(mstrKey) &nbsp;- 
            &nbsp;lKey) &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Wend 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;lKey &nbsp;= &nbsp;Len(mstrKey) &nbsp;- &nbsp;1 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;'遜埻峈坋輛秶杅趼 &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;For &nbsp;iLoop &nbsp;= &nbsp;lKey &nbsp;To 
            &nbsp;0 &nbsp;Step &nbsp;-1 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;sKey &nbsp;= &nbsp;Mid(mstrKey, 
            &nbsp;lKey &nbsp;- &nbsp;iLoop &nbsp;+ &nbsp;1, &nbsp;1) 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If 
            &nbsp;IsNumeric(sKey) &nbsp;Then &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iKey 
            &nbsp;= &nbsp;iKey &nbsp;+ &nbsp;CInt(sKey) &nbsp;* &nbsp;16 &nbsp;^ 
            &nbsp;iLoop &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;Else &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iKey &nbsp;= 
            &nbsp;iKey &nbsp;+ &nbsp;(Asc(UCase(sKey)) &nbsp;- &nbsp;55) &nbsp;* 
            &nbsp;16 &nbsp;^ &nbsp;iLoop &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;If &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;Next &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;sKey &nbsp;= &nbsp;"" 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;mstrKey &nbsp;= 
            &nbsp;CStr(iKey) &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;'遜埻峈坋鞠輛秶趼睫揹 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Do &nbsp;While 
            &nbsp;CDbl(mstrKey) &nbsp;&gt; &nbsp;35 &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iKey &nbsp;= 
            &nbsp;CDbl(mstrKey) &nbsp;/ &nbsp;36 &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lKey &nbsp;= &nbsp;InStr(1, 
            &nbsp;CStr(iKey), &nbsp;".") &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;If &nbsp;lKey &nbsp;&gt; &nbsp;0 
            &nbsp;Then &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mstrKey &nbsp;= 
            &nbsp;Left(CStr(iKey), &nbsp;lKey &nbsp;- &nbsp;1) &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;iKey &nbsp;= &nbsp;Round(CDbl("0." &nbsp;&amp; 
            &nbsp;Right(CStr(iKey), &nbsp;Len(CStr(iKey)) &nbsp;- &nbsp;lKey)) 
            &nbsp;* &nbsp;36) &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;Else &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mstrKey 
            &nbsp;= &nbsp;CStr(iKey) &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iKey &nbsp;= 
            &nbsp;0 &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;End &nbsp;If &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;If &nbsp;iKey &nbsp;&gt; &nbsp;9 &nbsp;Then 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;sKey &nbsp;= &nbsp;Chr(iKey &nbsp;+ 
            &nbsp;55) &nbsp;&amp; &nbsp;sKey &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Else &nbsp;<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;sKey &nbsp;= &nbsp;iKey &nbsp;&amp; &nbsp;sKey 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End 
            &nbsp;If &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Loop &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;If &nbsp;CDbl(mstrKey) &nbsp;&gt; &nbsp;9 
            &nbsp;Then &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;sKey &nbsp;= &nbsp;Chr(CDbl(mstrKey) &nbsp;+ &nbsp;55) 
            &nbsp;&amp; &nbsp;sKey &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;Else 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;sKey &nbsp;= &nbsp;mstrKey &nbsp;&amp; &nbsp;sKey 
            &nbsp;<BR>&nbsp; &nbsp; &nbsp; &nbsp;End &nbsp;If &nbsp;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;BreakRegKey &nbsp;= &nbsp;sKey &nbsp;<BR>End &nbsp;Function 
            &nbsp;<BR>&nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>软件是个人智慧的结晶,凝结了自己的血汗。好不容易编写了一个属于自己的软件,希望让别人共享自己的成果,希望别人能记住自己的大名,更希望别人能对自己的软件提出宝贵意见,同时也希望使自己可以方便地提供最新版本的软件给对自己的软件十分关心的用户,当然也要防止盗版(因为我们反对盗版)。这一切都可以用用户注册的方式解决。 
            &nbsp;<BR>谈到注册,便立即联想到注册码,但如何生成注册码,对于软件的设计者是一个十分关键的问题。首先,注册码需要有随机性,即注册码的生成每一次都不一样。其次,注册码需要有特定性,即注册码对于同一用户是一样的或是功能相同的。再次,注册码要有保密性,即不易被他人查到并破解。基于注册码的这种特点,首先就需要有一种合理的设计思路。 
            &nbsp;<BR>笔者所用的是一种明码——密匙——暗码的加密思路。具体说来:当加密时,先取一字符串作为明码(原码),再另取一字符串作密匙,利用某种算法(如常用的伪随机数加密算法)将这两段字符串进行变换及运算,从而获得另一字符串(暗码),再将暗码和密匙用文件保存起来,这样就不怕别人偷看了;当解密时,将密匙和暗码利用另一种解密算法进行变换和运算,还原得到明码。 
            &nbsp;<BR>这种方法的关键在于利用密匙和暗码能还原唯一的明码,而对于不同的用户应该有不同的明码和密匙,且密匙必须是唯一的(对于同一用户)。如果以上几点无法满足,将无法生成有效的注册码,切记切记!!! 
            &nbsp;<BR>下面用以上思路来设计我们自己的注册码: 
            &nbsp;<BR>首先,选择原码。当然选择注册的用户的用户名(最好是英文)来做注册码的原码,是一个很好的办法,推荐用英文的理由是:英文字符串比中文字符串在运算中容易控制,且不易出错;其次,选择密匙,按照密匙对于不同用户是不同且唯一的原则,我强烈建议选择硬盘的序列号作为密匙。因为从理论上讲一个硬盘的序列号是唯一的,而且不同分区的序列号也不相同。所以,我用硬盘上的C驱动器分区的序列号来做密匙。因为C区好像每台电脑上都有(什么?你没有?我倒!!!);再次,就是选择暗码了。当然了,暗码应该是由你利用以上思路做成的注册器来生成,并作为注册码寄给用户的啦^-^,有关注册器的设计待会儿再说。 
            &nbsp;<BR>理解了以上的注册码生成的思想后,下面就利用Micosoft &nbsp;的Visual 
            &nbsp;Basic6.0来完成这项设计工作。需要利用几个Windows的API函数:GetVolumeInformation用以获得硬盘的序列号、GetPrivateProfileString、WritePrivateProfileString用来读写INI文件。对于以上三个API函数的使用不作介绍了,现将其声明如下: 
            &nbsp;<BR>Private &nbsp;Declare &nbsp;Function 
            &nbsp;GetVolumeInformation &nbsp;Lib &nbsp;″kernel32″ &nbsp;Alias 
            &nbsp;″GetVolumeInformationA″ &nbsp;(ByVal &nbsp;lpRootPathName 
            &nbsp;As &nbsp;String, &nbsp;ByVal &nbsp;lpVolumeNameBuffer &nbsp;As 
            &nbsp;String, &nbsp;ByVal &nbsp;nVolumeNameSize &nbsp;As &nbsp;Long, 
            &nbsp;lpVolumeSerialNumber &nbsp;As &nbsp;Long, 
            &nbsp;lpMaximumComponentLength<BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<HR noShade SIZE=1 width=770>

<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
  <TBODY>
  <TR align=middle>
    <TD height=10 vAlign=bottom><A 
      href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A 
      href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A 
      href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> </TD>
    <TD align=middle rowSpan=3><A 
      href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG 
      border=0 height=48 src="注册码算法问题~!!.files/biaoshi.gif" width=40></A></TD></TR>
  <TR align=middle>
    <TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
  <TR align=middle>
    <TD vAlign=top><FONT face=Verdana>Copyright &copy; CSDN.net, Inc. All rights 
      reserved</FONT></TD></TR>
  <TR>
    <TD height=15></TD>
    <TD></TD></TR></TBODY></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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