蚊香 发表于 2008-9-19 23:42

1st Email Address Verifier V4.99注册算法浅析

【文章标题】: 1st Email Address Verifier V4.99注册算法浅析
【文章作者】: 蚊香
【作者邮箱】: xpi386com@gmail.com
【作者主页】: http://www.xpi386.com
【软件大小】: 1.23MB
【下载地址】: http://www.skycn.com/soft/29878.html
【使用工具】: PEiD,OllyDBG,计算器
【操作平台】: D版XP-SP3
【软件介绍】: 一款对邮件列表中的电子邮件地址进行验证的工具。
【作者声明】: 只是感兴趣,没有其他目的。失误之处敬请诸位大侠赐教!
--------------------------------------------------------------------------------
【详细过程】
PEiD瞄了一下,Delphi~~~ OD载入时发现卡的很~~~ 换个版本的OD情况依然~~~ 于是改为OD附加进程..这回成功了,哈~~
试注册发现弹框提示错误,于是用F12暂停找堆栈调用的方法很快找到关键的地方~~~~~

005C29F355PUSH EBP ; 用F12暂停法找到这里下断
005C29F468 CF2B5C00 PUSH XVerifie.005C2BCF
005C29F964:FF30 PUSH DWORD PTR FS:
005C29FC64:8920 MOV DWORD PTR FS:,ESP
005C29FF8D55 F0 LEA EDX,DWORD PTR SS:
005C2A028B45 FC MOV EAX,DWORD PTR SS:
005C2A058B80 08030000 MOV EAX,DWORD PTR DS:
005C2A0BE8 940AECFF CALL XVerifie.004834A4 ; 取用户名
005C2A108B45 F0 MOV EAX,DWORD PTR SS:
005C2A138D55 F4 LEA EDX,DWORD PTR SS:
005C2A16E8 1169E4FF CALL XVerifie.0040932C
005C2A1B837D F4 00CMP DWORD PTR SS:,0
005C2A1F0F84 5A010000 JE XVerifie.005C2B7F
005C2A258D55 E8 LEA EDX,DWORD PTR SS:
005C2A288B45 FC MOV EAX,DWORD PTR SS:
005C2A2B8B80 10030000 MOV EAX,DWORD PTR DS:
005C2A31E8 6E0AECFF CALL XVerifie.004834A4 ; 取注册码
005C2A368B45 E8 MOV EAX,DWORD PTR SS:
005C2A398D55 EC LEA EDX,DWORD PTR SS:
005C2A3CE8 EB68E4FF CALL XVerifie.0040932C
005C2A41837D EC 00CMP DWORD PTR SS:,0
005C2A450F84 34010000 JE XVerifie.005C2B7F
005C2A4B8D55 E0 LEA EDX,DWORD PTR SS:
005C2A4E8B45 FC MOV EAX,DWORD PTR SS:
005C2A518B80 10030000 MOV EAX,DWORD PTR DS:
005C2A57E8 480AECFF CALL XVerifie.004834A4 ; 注册码位数
005C2A5C8B45 E0 MOV EAX,DWORD PTR SS:
005C2A5F8D55 E4 LEA EDX,DWORD PTR SS:
005C2A62E8 C568E4FF CALL XVerifie.0040932C
005C2A678B45 E4 MOV EAX,DWORD PTR SS:
005C2A6A50PUSH EAX
005C2A6B8D55 DC LEA EDX,DWORD PTR SS:
005C2A6E8B45 FC MOV EAX,DWORD PTR SS:
005C2A718B80 08030000 MOV EAX,DWORD PTR DS:
005C2A77E8 280AECFF CALL XVerifie.004834A4 ; 用户名位数
005C2A7C8B55 DC MOV EDX,DWORD PTR SS:
005C2A7FA1 6C995C00 MOV EAX,DWORD PTR DS:
005C2A848B00MOV EAX,DWORD PTR DS:
005C2A868B80 44030000 MOV EAX,DWORD PTR DS:
005C2A8C33C9XOR ECX,ECX
005C2A8EE8 5573FAFF CALL XVerifie.00569DE8 ; 关键CALL,F7进
005C2A9384C0TEST AL,AL
005C2A9574 6A JE SHORT XVerifie.005C2B01 ; 跳向失败
005C2A97A1 3C975C00 MOV EAX,DWORD PTR DS:
005C2A9CC600 01 MOV BYTE PTR DS:,1
005C2A9F6A 40 PUSH 40
005C2AA18D55 D8 LEA EDX,DWORD PTR SS:
005C2AA4A1 189B5C00 MOV EAX,DWORD PTR DS:
005C2AA98B00MOV EAX,DWORD PTR DS:
005C2AABE8 C009EEFF CALL XVerifie.004A3470
005C2AB08B45 D8 MOV EAX,DWORD PTR SS:
005C2AB3E8 E422E4FF CALL XVerifie.00404D9C
005C2AB850PUSH EAX
005C2AB98D55 D4 LEA EDX,DWORD PTR SS:
005C2ABCA1 4C9B5C00 MOV EAX,DWORD PTR DS:
005C2AC1E8 FE41E4FF CALL XVerifie.00406CC4
005C2AC68B45 D4 MOV EAX,DWORD PTR SS:
005C2AC9E8 CE22E4FF CALL XVerifie.00404D9C
005C2ACE8BD0MOV EDX,EAX
005C2AD0A1 189B5C00 MOV EAX,DWORD PTR DS:
005C2AD58B00MOV EAX,DWORD PTR DS:
005C2AD759POP ECX
005C2AD8E8 FB0FEEFF CALL XVerifie.004A3AD8 ; 正确提示
005C2ADD8B15 3C975C00 MOV EDX,DWORD PTR DS:; XVerifie.005CCFB8
005C2AE38A12MOV DL,BYTE PTR DS:
005C2AE5A1 6C995C00 MOV EAX,DWORD PTR DS:
005C2AEA8B00MOV EAX,DWORD PTR DS:
005C2AEC8B80 CC030000 MOV EAX,DWORD PTR DS:
005C2AF2E8 BD4FFFFF CALL XVerifie.005B7AB4
005C2AF78B45 FC MOV EAX,DWORD PTR SS:
005C2AFAE8 85D7EDFF CALL XVerifie.004A0284
005C2AFFEB 3C JMP SHORT XVerifie.005C2B3D
005C2B016A 10 PUSH 10
005C2B038D55 D0 LEA EDX,DWORD PTR SS:
005C2B06A1 D0955C00 MOV EAX,DWORD PTR DS:
005C2B0BE8 B441E4FF CALL XVerifie.00406CC4
005C2B108B45 D0 MOV EAX,DWORD PTR SS:
005C2B13E8 8422E4FF CALL XVerifie.00404D9C
005C2B1850PUSH EAX
005C2B198D55 CC LEA EDX,DWORD PTR SS:
005C2B1CA1 B4965C00 MOV EAX,DWORD PTR DS:
005C2B21E8 9E41E4FF CALL XVerifie.00406CC4
005C2B268B45 CC MOV EAX,DWORD PTR SS:
005C2B29E8 6E22E4FF CALL XVerifie.00404D9C
005C2B2E8BD0MOV EDX,EAX
005C2B30A1 189B5C00 MOV EAX,DWORD PTR DS:
005C2B358B00MOV EAX,DWORD PTR DS:
005C2B3759POP ECX
005C2B38E8 9B0FEEFF CALL XVerifie.004A3AD8 ; 错误提示
005C2B3DA1 6C995C00 MOV EAX,DWORD PTR DS:
005C2B428B00MOV EAX,DWORD PTR DS:
005C2B448B80 44030000 MOV EAX,DWORD PTR DS:
005C2B4AFF70 48 PUSH DWORD PTR DS:
005C2B4D68 E42B5C00 PUSH XVerifie.005C2BE4
005C2B52A1 6C995C00 MOV EAX,DWORD PTR DS:
005C2B578B00MOV EAX,DWORD PTR DS:
005C2B598B80 44030000 MOV EAX,DWORD PTR DS:
005C2B5FFF70 5C PUSH DWORD PTR DS:
005C2B628D45 C8 LEA EAX,DWORD PTR SS:
005C2B65BA 03000000 MOV EDX,3
005C2B6AE8 F520E4FF CALL XVerifie.00404C64
005C2B6F8B45 C8 MOV EAX,DWORD PTR SS:
005C2B728B15 3C975C00 MOV EDX,DWORD PTR DS:; XVerifie.005CCFB8
005C2B788A12MOV DL,BYTE PTR DS:
005C2B7AE8 5553FFFF CALL XVerifie.005B7ED4
005C2B7F33C0XOR EAX,EAX
005C2B815APOP EDX
005C2B8259POP ECX
005C2B8359POP ECX
005C2B8464:8910 MOV DWORD PTR FS:,EDX
005C2B8768 D62B5C00 PUSH XVerifie.005C2BD6
005C2B8C8D45 C8 LEA EAX,DWORD PTR SS:
005C2B8FBA 05000000 MOV EDX,5
005C2B94E8 4B1DE4FF CALL XVerifie.004048E4
005C2B998D45 DC LEA EAX,DWORD PTR SS:
005C2B9CBA 02000000 MOV EDX,2
005C2BA1E8 3E1DE4FF CALL XVerifie.004048E4
005C2BA68D45 E4 LEA EAX,DWORD PTR SS:
005C2BA9E8 121DE4FF CALL XVerifie.004048C0
005C2BAE8D45 E8 LEA EAX,DWORD PTR SS:
005C2BB1E8 0A1DE4FF CALL XVerifie.004048C0
005C2BB68D45 EC LEA EAX,DWORD PTR SS:
005C2BB9E8 021DE4FF CALL XVerifie.004048C0
005C2BBE8D45 F0 LEA EAX,DWORD PTR SS:
005C2BC1E8 FA1CE4FF CALL XVerifie.004048C0
005C2BC68D45 F4 LEA EAX,DWORD PTR SS:
005C2BC9E8 F21CE4FF CALL XVerifie.004048C0
005C2BCEC3RETN
005C2BCF^ E9 AC15E4FF JMP XVerifie.00404180
005C2BD4^ EB B6 JMP SHORT XVerifie.005C2B8C
005C2BD68BE5MOV ESP,EBP
005C2BD85DPOP EBP
005C2BD9C3RETN

进入 005C2A8E

00569DE855PUSH EBP
00569DE98BECMOV EBP,ESP
00569DEB83C4 E8 ADD ESP,-18
00569DEE53PUSH EBX
00569DEF33DBXOR EBX,EBX
00569DF1895D E8 MOV DWORD PTR SS:,EBX
00569DF4895D EC MOV DWORD PTR SS:,EBX
00569DF7894D F4 MOV DWORD PTR SS:,ECX
00569DFA8955 F8 MOV DWORD PTR SS:,EDX
00569DFD8945 FC MOV DWORD PTR SS:,EAX
00569E008B45 F8 MOV EAX,DWORD PTR SS:
00569E03E8 84AFE9FF CALL XVerifie.00404D8C
00569E088B45 F4 MOV EAX,DWORD PTR SS:
00569E0BE8 7CAFE9FF CALL XVerifie.00404D8C
00569E108B45 08 MOV EAX,DWORD PTR SS:
00569E13E8 74AFE9FF CALL XVerifie.00404D8C
00569E1833C0XOR EAX,EAX
00569E1A55PUSH EBP
00569E1B68 F79E5600 PUSH XVerifie.00569EF7
00569E2064:FF30 PUSH DWORD PTR FS:
00569E2364:8920 MOV DWORD PTR FS:,ESP
00569E268B45 F8 MOV EAX,DWORD PTR SS:
00569E29E8 76ADE9FF CALL XVerifie.00404BA4
00569E2E8B55 FC MOV EDX,DWORD PTR SS:
00569E313B42 4C CMP EAX,DWORD PTR DS:; 用户名位数必须小于64H
00569E347F 1C JG SHORT XVerifie.00569E52
00569E368B45 F8 MOV EAX,DWORD PTR SS:
00569E39E8 66ADE9FF CALL XVerifie.00404BA4
00569E3E8B55 FC MOV EDX,DWORD PTR SS:
00569E413B42 50 CMP EAX,DWORD PTR DS:; 用户名位数必须大于等于3
00569E447C 0C JL SHORT XVerifie.00569E52
00569E468B45 08 MOV EAX,DWORD PTR SS:
00569E49E8 56ADE9FF CALL XVerifie.00404BA4
00569E4E85C0TEST EAX,EAX
00569E5075 06 JNZ SHORT XVerifie.00569E58
00569E52C645 F3 00MOV BYTE PTR SS:,0
00569E56EB 6F JMP SHORT XVerifie.00569EC7
00569E588D55 EC LEA EDX,DWORD PTR SS:
00569E5B8B45 08 MOV EAX,DWORD PTR SS:
00569E5EE8 59F2E9FF CALL XVerifie.004090BC
00569E638B55 EC MOV EDX,DWORD PTR SS:
00569E668D45 08 LEA EAX,DWORD PTR SS:
00569E69E8 EAAAE9FF CALL XVerifie.00404958
00569E6E8D4D E8 LEA ECX,DWORD PTR SS:
00569E718B55 F8 MOV EDX,DWORD PTR SS:
00569E748B45 FC MOV EAX,DWORD PTR SS:
00569E77E8 D4FBFFFF CALL XVerifie.00569A50 ; 经过此CALL后出现真码,F7进去
00569E7C8B45 E8 MOV EAX,DWORD PTR SS:
00569E7F8B55 08 MOV EDX,DWORD PTR SS:
00569E82E8 ADF2E9FF CALL XVerifie.00409134 ; 真假码比较
00569E8785C0TEST EAX,EAX
00569E8974 06 JE SHORT XVerifie.00569E91 ; 关键跳转
00569E8BC645 F3 00MOV BYTE PTR SS:,0
00569E8FEB 36 JMP SHORT XVerifie.00569EC7
00569E918B45 FC MOV EAX,DWORD PTR SS:
00569E9483C0 48 ADD EAX,48
00569E978B55 F8 MOV EDX,DWORD PTR SS:
00569E9AE8 75AAE9FF CALL XVerifie.00404914
00569E9F8B45 FC MOV EAX,DWORD PTR SS:
00569EA283C0 54 ADD EAX,54
00569EA58B55 F4 MOV EDX,DWORD PTR SS:
00569EA8E8 67AAE9FF CALL XVerifie.00404914
00569EAD8B45 FC MOV EAX,DWORD PTR SS:
00569EB083C0 5C ADD EAX,5C
00569EB38B55 08 MOV EDX,DWORD PTR SS:
00569EB6E8 59AAE9FF CALL XVerifie.00404914
00569EBB8B45 FC MOV EAX,DWORD PTR SS:
00569EBEE8 49020000 CALL XVerifie.0056A10C
00569EC3C645 F3 01MOV BYTE PTR SS:,1
00569EC733C0XOR EAX,EAX
00569EC95APOP EDX
00569ECA59POP ECX
00569ECB59POP ECX
00569ECC64:8910 MOV DWORD PTR FS:,EDX
00569ECF68 FE9E5600 PUSH XVerifie.00569EFE
00569ED48D45 E8 LEA EAX,DWORD PTR SS:
00569ED7BA 02000000 MOV EDX,2
00569EDCE8 03AAE9FF CALL XVerifie.004048E4
00569EE18D45 F4 LEA EAX,DWORD PTR SS:
00569EE4BA 02000000 MOV EDX,2
00569EE9E8 F6A9E9FF CALL XVerifie.004048E4
00569EEE8D45 08 LEA EAX,DWORD PTR SS:
00569EF1E8 CAA9E9FF CALL XVerifie.004048C0
00569EF6C3RETN
00569EF7^ E9 84A2E9FF JMP XVerifie.00404180
00569EFC^ EB D6 JMP SHORT XVerifie.00569ED4
00569EFE8A45 F3 MOV AL,BYTE PTR SS:
00569F015BPOP EBX
00569F028BE5MOV ESP,EBP
00569F045DPOP EBP
00569F05C2 0400 RETN 4

进入 00569E77

00569A5055PUSH EBP
00569A518BECMOV EBP,ESP
00569A5383C4 DC ADD ESP,-24
00569A5653PUSH EBX
00569A5733DBXOR EBX,EBX
00569A59895D DC MOV DWORD PTR SS:,EBX
00569A5C895D E8 MOV DWORD PTR SS:,EBX
00569A5F894D F4 MOV DWORD PTR SS:,ECX
00569A628955 F8 MOV DWORD PTR SS:,EDX
00569A658945 FC MOV DWORD PTR SS:,EAX
00569A688B45 F8 MOV EAX,DWORD PTR SS:
00569A6BE8 1CB3E9FF CALL XVerifie.00404D8C
00569A7033C0XOR EAX,EAX
00569A7255PUSH EBP
00569A7368 8E9B5600 PUSH XVerifie.00569B8E
00569A7864:FF30 PUSH DWORD PTR FS:
00569A7B64:8920 MOV DWORD PTR FS:,ESP
00569A7E8B45 F8 MOV EAX,DWORD PTR SS:
00569A81E8 1EB1E9FF CALL XVerifie.00404BA4
00569A868B55 FC MOV EDX,DWORD PTR SS:
00569A893B42 4C CMP EAX,DWORD PTR DS:; 用户名位数小于64H
00569A8C7F 10 JG SHORT XVerifie.00569A9E
00569A8E8B45 F8 MOV EAX,DWORD PTR SS:
00569A91E8 0EB1E9FF CALL XVerifie.00404BA4
00569A968B55 FC MOV EDX,DWORD PTR SS:
00569A993B42 50 CMP EAX,DWORD PTR DS:; 用户名位数大于等于3
00569A9C7D 0D JGE SHORT XVerifie.00569AAB
00569A9E8B45 F4 MOV EAX,DWORD PTR SS:
00569AA1E8 1AAEE9FF CALL XVerifie.004048C0
00569AA6E9 BD000000 JMP XVerifie.00569B68
00569AAB8B45 F8 MOV EAX,DWORD PTR SS:
00569AAEE8 F1B0E9FF CALL XVerifie.00404BA4
00569AB38945 F0 MOV DWORD PTR SS:,EAX
00569AB6EB 39 JMP SHORT XVerifie.00569AF1
00569AB88B45 F8 MOV EAX,DWORD PTR SS:
00569ABB8B55 F0 MOV EDX,DWORD PTR SS:
00569ABE8A4410 FF MOV AL,BYTE PTR DS: ; 从右至左依次用户名ASCII
00569AC225 FF000000 AND EAX,0FF
00569AC733D2XOR EDX,EDX
00569AC952PUSH EDX
00569ACA50PUSH EAX
00569ACB8B45 FC MOV EAX,DWORD PTR SS:
00569ACE8B50 6C MOV EDX,DWORD PTR DS:
00569AD18B40 68 MOV EAX,DWORD PTR DS:
00569AD4E8 0BC0E9FF CALL XVerifie.00405AE4 ; 分别被常数 04B234EEH 取余
00569AD952PUSH EDX
00569ADA50PUSH EAX
00569ADB8D45 DC LEA EAX,DWORD PTR SS:
00569ADEE8 21FDE9FF CALL XVerifie.00409804 ; 转10进制
00569AE38B55 DC MOV EDX,DWORD PTR SS:
00569AE68D45 E8 LEA EAX,DWORD PTR SS:
00569AE9E8 BEB0E9FF CALL XVerifie.00404BAC
00569AEEFF4D F0 DEC DWORD PTR SS:
00569AF18B45 F8 MOV EAX,DWORD PTR SS:
00569AF4E8 ABB0E9FF CALL XVerifie.00404BA4
00569AF983E8 06 SUB EAX,6
00569AFC3B45 F0 CMP EAX,DWORD PTR SS:
00569AFF7F 06 JG SHORT XVerifie.00569B07
00569B01837D F0 00CMP DWORD PTR SS:,0; 控制循环,从右至左取7位(如果够7位的话)
00569B05^ 7F B1 JG SHORT XVerifie.00569AB8
00569B078D55 EC LEA EDX,DWORD PTR SS:
00569B0A8B45 E8 MOV EAX,DWORD PTR SS:; 连接上面得到的(小于等于)7组数字,作为一个10进制整数,设为sn1
00569B0DE8 DEC0E9FF CALL XVerifie.00405BF0
00569B128945 E0 MOV DWORD PTR SS:,EAX
00569B158955 E4 MOV DWORD PTR SS:,EDX
00569B188B45 FC MOV EAX,DWORD PTR SS:
00569B1B8378 60 00CMP DWORD PTR DS:,0
00569B1F7F 12 JG SHORT XVerifie.00569B33
00569B21FF75 E4 PUSH DWORD PTR SS:
00569B24FF75 E0 PUSH DWORD PTR SS:
00569B278B55 F4 MOV EDX,DWORD PTR SS:
00569B2A33C0XOR EAX,EAX
00569B2CE8 43FDE9FF CALL XVerifie.00409874
00569B31EB 35 JMP SHORT XVerifie.00569B68
00569B33FF75 E4 PUSH DWORD PTR SS:
00569B36FF75 E0 PUSH DWORD PTR SS:
00569B398B55 F4 MOV EDX,DWORD PTR SS:
00569B3C8B45 FC MOV EAX,DWORD PTR SS:
00569B3F8B40 60 MOV EAX,DWORD PTR DS:
00569B42E8 2DFDE9FF CALL XVerifie.00409874
00569B478B45 F4 MOV EAX,DWORD PTR SS:
00569B4A8B00MOV EAX,DWORD PTR DS: ; 将上面得到的sn1转换成16进制(若不足12位,则前面补0至12位),设为sn2(最终注册码)
00569B4CE8 53B0E9FF CALL XVerifie.00404BA4
00569B518BC8MOV ECX,EAX
00569B538B45 FC MOV EAX,DWORD PTR SS:
00569B562B48 60 SUB ECX,DWORD PTR DS:
00569B598B45 FC MOV EAX,DWORD PTR SS:
00569B5C8B50 60 MOV EDX,DWORD PTR DS:
00569B5F42INC EDX
00569B608B45 F4 MOV EAX,DWORD PTR SS:
00569B63E8 D4B2E9FF CALL XVerifie.00404E3C
00569B6833C0XOR EAX,EAX
00569B6A5APOP EDX
00569B6B59POP ECX
00569B6C59POP ECX
00569B6D64:8910 MOV DWORD PTR FS:,EDX
00569B7068 959B5600 PUSH XVerifie.00569B95
00569B758D45 DC LEA EAX,DWORD PTR SS:
00569B78E8 43ADE9FF CALL XVerifie.004048C0
00569B7D8D45 E8 LEA EAX,DWORD PTR SS:
00569B80E8 3BADE9FF CALL XVerifie.004048C0
00569B858D45 F8 LEA EAX,DWORD PTR SS:
00569B88E8 33ADE9FF CALL XVerifie.004048C0
00569B8DC3RETN
00569B8E^ E9 EDA5E9FF JMP XVerifie.00404180
00569B93^ EB E0 JMP SHORT XVerifie.00569B75
00569B955BPOP EBX
00569B968BE5MOV ESP,EBP
00569B985DPOP EBP
00569B99C3RETN

--------------------------------------------------------------------------------
【算法总结】
首先用户名长度L必须满足3≤L<100.如果大于7位,则只取后7位.
从右至左取用户名的ASCII,分别被78787822(04B234EEH)取余,余数依次连接作为一个10进制整数sn1.
将sn1转成16进制数sn2.若sn2长度不足12,则在其前面补0至12位(最终注册码).
注册信息以加密的形式保存在注册表中 ~~~

KeyGen核心源码(VB Code):

&#39;需要添加一个支持10进制天文数字转16进制的模块.
&#39;两个文本框,一个Command按钮.
Private Sub Command1_Click()
Dim Name, Name1, Name2 As String
Dim L, I As Integer
Dim sn1, sn2 As String
Name = CStr(Text1.Text)
Name1 = StrReverse(Name)
L = Len(Name)
If L < 3 Or L >= 100 Then
Text2.Text = "用户名位数大于等于3,小于100"
ElseIf L >= 3 And L < 8 Then
For I = 1 To L
sn1 = sn1 & (78787822 Mod Asc(Mid(Name1, I, 1)))
Next I
sn2 = dectohex(sn1)
For I = 1 To (12 - Len(sn2))
sn2 = "0" & sn2
Next I
Text2.Text = sn2

Else
Name2 = Left(Name1, 7)
For I = 1 To 7
sn1 = sn1 & (78787822 Mod Asc(Mid(Name2, I, 1)))
Next I
sn2 = dectohex(sn1)
For I = 1 To (12 - Len(sn2))
sn2 = "0" & sn2
Next I
Text2.Text = sn2

End If
End Sub

附:网上找的一个支持10进制天文数字转16进制的模块代码:


Dim largehex As String, largedec As String, start As Long, Y(20) As String

&#39;预备函数
Function sums(ByVal X As String, ByVal Y As String) As String &#39; sum of two hugehexnum(两个大数之和)
Dim max As Long, temp As Long, I As Long, result As Variant
max = IIf(Len(X) >= Len(Y), Len(X), Len(Y))
X = Right(String(max, "0") & X, max)
Y = Right(String(max, "0") & Y, max)
ReDim result(0 To max)
For I = max To 1 Step -1
result(I) = Val(Mid(X, I, 1)) + Val(Mid(Y, I, 1))
Next
For I = max To 1 Step -1
temp = result(I) \ 10
result(I) = result(I) Mod 10
result(I - 1) = result(I - 1) + temp
Next
If result(0) = 0 Then result(0) = ""
sums = Join(result, "")
Erase result

End Function

Function multi(ByVal X As String, ByVal Y As String) As String &#39;multi of two huge hexnum(两个大数之积)
Dim result As Variant
Dim xl As Long, yl As Long, temp As Long, I As Long
xl = Len(Trim(X))
yl = Len(Trim(Y))

ReDim result(1 To xl + yl)
For I = 1 To xl
For temp = 1 To yl
result(I + temp) = result(I + temp) + Val(Mid(X, I, 1)) * Val(Mid(Y, temp, 1))
Next
Next

For I = xl + yl To 2 Step -1
temp = result(I) \ 10
result(I) = result(I) Mod 10
result(I - 1) = result(I - 1) + temp
Next

If result(1) = "0" Then result(1) = ""
multi = Join(result, "")
Erase result

End Function
Function POWERS(ByVal X As Integer) As String &#39; GET 16777216^X,ie 16^(6*x)(16777216的X 次方)
POWERS = 1
Dim I As Integer
For I = 1 To X
POWERS = multi(POWERS, CLng(&H1000000))
Next
End Function
Function half(ByVal X As String) As String &#39;get half of x(取半)
X = 0 & X
Dim I As Long
ReDim result(2 To Len(X)) As String
For I = 2 To Len(X)
result(I) = CStr(Val(Mid(X, I, 1)) \ 2 + IIf(Val(Mid(X, I - 1, 1)) Mod 2 = 1, 5, 0))
Next
half = Join(result, "")
If Left(half, 1) = "0" Then half = Right(half, Len(half) - 1) &#39; no zero ahead
End Function

&#39;另一个有用的函数:
Function POWERXY(ByVal X As Integer, ByVal Y As Integer) As String &#39;GETX^Y(X 的 Y 次方)
Dim I As Integer
POWERXY = X
For I = 2 To Y
POWERXY = multi(POWERXY, X)
Next
End Function

&#39;进制转换函数:

&#39;16 to 10
Function HEXTODEC(ByVal X As String) As String
Dim A() As String, I As Long, UNIT As Integer
For I = 1 To Len(X)
If Not IsNumeric("&h" & Mid(X, I, 1)) Then MsgBox "NOT A HEX FORMAT!", 64, "INFO": Exit Function
Next
X = String((6 - Len(X) Mod 6) Mod 6, "0") & X

UNIT = Len(X) \ 6 - 1
ReDim A(UNIT)
For I = 0 To UNIT
A(I) = CLng("&h" & Mid(X, I * 6 + 1, 6))
Next
For I = 0 To UNIT
A(I) = multi(A(I), POWERS(UNIT - I))
HEXTODEC = sums(HEXTODEC, A(I))
Next
End Function

&#39; 10 to 16
Function dectohex(ByVal hugenum As String) As String &#39; trans hugenum to hex
Do While Len(hugenum) > 2
dectohex = Hex(Val(Right(hugenum, 4)) Mod 16) & dectohex
For I = 1 To 4 &#39;devide hugenumby 16
hugenum = half(hugenum)
Next
Loop
dectohex = Hex(Val(hugenum)) & dectohex
End Function

Private Sub Form_Load()
For I = 0 To 20
Y(I) = "1234567890ABCDEF"
Next

largehex = Join(Y, "")
End Sub

--------------------------------------------------------------------------------
【版权声明】: 本文由 蚊香 原创,转载请注明作者并保持文章的完整,谢谢!

wgz001 发表于 2008-9-20 08:23

学习算法分析 多谢了
页: [1]
查看完整版本: 1st Email Address Verifier V4.99注册算法浅析