﻿{"id":36220,"date":"2012-04-05T22:53:37","date_gmt":"2012-04-05T14:53:37","guid":{"rendered":"http:\/\/www.lanmaowang.com\/?p=36220"},"modified":"2015-04-01T22:59:05","modified_gmt":"2015-04-01T14:59:05","slug":"delphi-program-timelines-and-encryption","status":"publish","type":"post","link":"http:\/\/www.lanmaowang.com\/?p=36220","title":{"rendered":"Delphi\u7a0b\u5e8f\u7684\u65f6\u9650\u548c\u52a0\u5bc6"},"content":{"rendered":"<p><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">Delphi\u7a0b\u5e8f\u7684\u65f6\u9650\u548c\u52a0\u5bc6<\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">\u672c\u4f8b\u4e2dTRegistry\u662f\u5173\u952e\u7c7b\uff0cDelphi 4.0\u4e0d\u80fd\u81ea\u884c\u52a0\u5165\uff0c\u9700\u5728uses\u90e8\u5206\u624b\u5de5\u52a0\u5165&amp;ldquo;registry&amp;rdquo;\uff0c\u901a\u8fc7\u5176\u65b9\u6cd5&amp;ldquo;ReadString&amp;rdquo;\u548c&amp;ldquo;WriteString&amp;rdquo;\u6765\u8bfb\u51fa\u548c\u5199\u5165\u5b57\u7b26\uff0c\u4ea6\u53ef\u901a\u8fc7\u5176\u65b9\u6cd5&amp;ldquo;ReadDate&amp;rdquo;\u548c&amp;ldquo;WriteDate&amp;rdquo;\u6765\u8bfb\u51fa\u548c\u5199\u5165\u65e5\u671f\u3002<span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">\u7a0b\u5e8f\u7b2c\u4e00\u6b21\u8fd0\u884c\u5c31\u5199\u5165\u5176\u8fd0\u884c\u65f6\u95f4\uff0c\u5e94\u7528\u671f\u9650\u4e3a30\u5929\uff0c\u8d85\u8fc730\u5929\u5c31\u4e0d\u518d\u8fd0\u884c\u3002\u5168\u5c40\u53d8\u91cfNoRegistry\u3001SpareDays\u6765\u5206\u522b\u5224\u65ad\u662f\u5426\u6ce8\u518c\u548c\u5269\u4f59\u671f\u9650\uff0c\u81ea\u5b9a\u4e49\u51fd\u6570Encrypt\u4e3a\u7528\u6237\u540d\u5230\u5bc6\u7801\u7684\u53d8\u6362\u51fd\u6570\u3002<\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">\u4e00\u3001\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u901a\u8fc7\u641c\u7d22\u6ce8\u518c\u8868\uff0c\u5224\u65ad\u662f\u5426\u7b2c\u4e00\u6b21\u8fd0\u884c\u548c\u662f\u5426\u6ce8\u518c\uff0c\u6765\u786e\u5b9a\u7a0b\u5e8f\u662f\u5426\u8fd0\u884c\u3002<span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><\/span><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><\/span><\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TForm1.FormCreate(Sender:&nbsp;TObject);\r\nvar\r\nReg:Tregistry;\r\nKeyName,TempCode,TempName,TempStr:string;\r\nSame:Integer;\r\nFirstDate,NowDate:Tdatetime;\r\nNumberOfDays:real;\r\nbegin\r\nNoRegistry:=true;\r\nNowDate:=date;&nbsp;\/\/\u53d6\u5f97\u8fd0\u884c\u65f6\u7cfb\u7edf\u65e5\u671f\r\ntry\r\n\/\/\u521b\u5efa\u6ce8\u518c\u8868\uff0c\u6709\u8be5\u952e\u5219\u8bfb\u53d6\uff0c\u65e0\u5219\u521b\u5efa\r\nReg:=Tregistry.Create&nbsp;;\r\nReg.RootKey&nbsp;:=hkey_local_machine;\r\nKeyName:=&#39;Software\\jsjb\\Example&#39;;\r\nif&nbsp;Reg.OpenKey(KeyName,true)&nbsp;then\r\nbegin\r\nTempName:=Reg.ReadString(&#39;UsrName&#39;);\r\nTempCode:=Reg.ReadString(&#39;Passwd&#39;);\r\n\/\/\u8bfb\u53d6\u7528\u6237\u540d\uff0c\u6ce8\u518c\u53f7\r\ntry\r\nFirstDate:=Reg.ReadDate(&#39;Date&#39;);\r\n\/\/\u975e\u7b2c\u4e00\u6b21\u5219\u8bfb\u5165\u7b2c\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4\r\nexcept\r\nReg.WriteDate(&#39;Date&#39;,NowDate);\r\n\/\/&nbsp;\u82e5\u4e3a\u7b2c\u4e00\u6b21\u8fd0\u884c\uff0c\u5219\u5199\u5165\u7cfb\u7edf\u65e5\u671f\r\nFirstDate:=NowDate;\r\nend;\r\nend&nbsp;;\r\nreg.CloseKey&nbsp;;\r\nfinally\r\nreg.Free&nbsp;;\r\nend;\r\nTempStr:=Encrypt(TempName);\r\n\/\/\u901a\u8fc7\u81ea\u5b9a\u4e49\u51fd\u6570Encrypt\uff08\uff09\u6765\u83b7\u53d6\u5bc6\u7801\r\nSame:=CompareText(TempStr,TempCode);\r\n\/\/\u6bd4\u8f83\u5bc6\u7801\r\nif&nbsp;TempName&lt;&gt;&#39;&#39;&nbsp;then\r\nif&nbsp;Same=0&nbsp;then\r\nNoRegistry:=false;\r\n\/\/\u9a8c\u8bc1\u5bc6\u7801\uff0c\u901a\u8fc7NoRegistry\u4e3afalse\r\nif&nbsp;NoRegistry&nbsp;then\r\nbegin&nbsp;\/\/\u82e5\u672a\u6ce8\u518c...\r\nNumberOfDays:=Nowdate-FirstDate;\r\nSpareDays:=round(31-NumberOfDays);\r\nLabel1.Caption&nbsp;:=FloatToStr(SpareDays);\r\nif((NumberOfDays&gt;31)&nbsp;or&nbsp;(NumberOfDays&lt;-1))&nbsp;then\r\nbegin\r\nshowmessage(&#39;\u7a0b\u5e8f\u672a\u6ce8\u518c\u8d85\u8fc7\u8bd5\u7528\u671f\u6216\u66f4\u6539\u7cfb\u7edf\u65f6\u95f4\uff0c\u5c06\u7ec8\u6b62\u8fd0\u884c!&#39;);\r\napplication.Terminate;\/\/\u8d85\u8fc730\u5929\uff0c\u5219\u7981\u6b62\u8fd0\u884c\r\nend;\r\nend;\r\nend;<\/pre>\n<p><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">\u4e8c\u3001\u6ce8\u518c\u8fc7\u7a0b\uff0c\u5176\u54cd\u5e94\u5165\u53e3\u53ef\u653e\u4e8e&quot;About&quot;\u5185\u3002<span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><\/span><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><span class=\"Apple-converted-space\"><\/span><\/span><\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TAbout.Button1Click(Sender:&nbsp;TObject);\r\nvar\r\nInptName,InptCode,RealCode:String;\r\nSame:Integer;\r\nReg:Tregistry;\r\nKeyname:String;\r\nbegin\r\nif&nbsp;NoRegistry&nbsp;then&nbsp;\/\/\u672a\u6ce8\u518c\u65f6\u505a\r\nbegin\r\nRealCode:=&#39;&#39;;\r\nInptName:=&nbsp;InputBox(&#39;\u6ce8\u518c&#39;,&nbsp;&#39;\u8f93\u5165\u4f60\u7684\u540d\u5b57&#39;,&nbsp;&#39;&#39;);\r\nif&nbsp;InptName&lt;&gt;&#39;&#39;&nbsp;then\r\nbegin\r\nInptCode:=&nbsp;InputBox(&#39;\u6ce8\u518c&#39;,&nbsp;&#39;\u8f93\u5165\u6ce8\u518c\u53f7&#39;,&nbsp;&#39;&#39;);\r\nRealCode:=Encrypt(InptName);\r\nSame:=CompareText(RealCode,InptCode);\r\nif&nbsp;(Same&lt;&gt;0)&nbsp;then\r\nshowmessage(&#39;\u6ce8\u518c\u53f7\u7801\u4e0d\u5bf9,\u6ce8\u518c\u672a\u6210\u529f\uff01&#39;)\r\nelse\r\nbegin\r\n\/\/\u5bc6\u7801\u5339\u914d\u65f6\u505a\uff1a\u628a\u7528\u6237\u540d\u3001\u5bc6\u7801\u5199\u5165\u6ce8\u518c\u8868\r\nTry\r\nReg:=Tregistry.Create&nbsp;;\r\nReg.RootKey&nbsp;:=hkey_local_machine;\r\nKeyName:=&#39;Software\\jsjb\\Example&#39;;\r\nif&nbsp;Reg.OpenKey(KeyName,true)&nbsp;then\r\nbegin\r\nReg.WriteString(&#39;Passwd&#39;,InptCode);\r\nReg.WriteString(&#39;UsrName&#39;,InptName);\r\nend;\r\nreg.CloseKey&nbsp;;\r\nfinally\r\nReg.Free&nbsp;;\r\nend;\r\nNoRegistry:=false;\r\n\/\/\u53ef\u4fee\u6539\u6ce8\u518c\u540e\u7684\u754c\u9762\r\nend;\r\nend;\r\nend;\r\nend;<\/pre>\n<p><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">\u4e09\u3001\u5bc6\u7801\u7684\u53d8\u6362\u51fd\u6570\u3002\u6b64\u53d8\u6362\u51fd\u6570\u53ef\u7531\u8bfb\u8005\u81ea\u7531\u53d1\u6325\uff0c\u5728\u6b64\uff0c\u4ec5\u793a\u4e00\u4f8b\u800c\u5df2\u3002<span class=\"Apple-converted-space\">&nbsp;<\/span><\/span><br style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"\/><span style=\"background-color: rgb(255, 255, 255); font-family: \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 16px; orphans: 2; widows: 2;\"><\/span><span style=\"widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; letter-spacing: normal; display: inline !important; font: 12px\/16px \u5b8b\u4f53, Verdana, Arial, Helvetica, sans-serif; orphans: 2; float: none; color: rgb(0,0,0); word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\"><span class=\"Apple-converted-space\"><\/span><\/span><\/p>\n<pre class=\"brush:delphi;toolbar:false\">Function&nbsp;TForm1.Encrypt(TempStr:string):string;\r\nVar\r\nStr1:String;\r\ni,j:Integer;\r\nBegin\r\nStr1:=&#39;&#39;;\r\nFor&nbsp;i:=1&nbsp;to&nbsp;Length(TempStr)&nbsp;do\r\nbegin\r\nj:=(i\u3000i\u3000i\u3000i&nbsp;mod&nbsp;(i+30))+(i\u3000i&nbsp;mod&nbsp;(i+20))+i\u30003+1;\r\nStr1:=Str1+chr(ord(TempStr)+j);\r\nj:=(i\u3000i\u3000i\u3000i&nbsp;mod&nbsp;(i+30))+(i\u3000i&nbsp;mod&nbsp;(i+20))+i\u30003+1;\r\nStr1:=Str1+chr(ord(TempStr)+j);\r\nEnd;\r\nResult:=Str1;\r\nend;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Delphi\u7a0b\u5e8f\u7684\u65f6\u9650\u548c\u52a0\u5bc6\u672c\u4f8b\u4e2dTRegistry\u662f\u5173\u952e\u7c7b\uff0cDelphi 4.0\u4e0d\u80fd\u81ea\u884c\u52a0\u5165\uff0c\u9700\u5728uses\u90e8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[193],"tags":[198,215,216],"_links":{"self":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36220"}],"collection":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36220"}],"version-history":[{"count":1,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36220\/revisions"}],"predecessor-version":[{"id":36221,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36220\/revisions\/36221"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/media\/36149"}],"wp:attachment":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36220"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}