Base64加密算法相对来说简单一些。
【理论准备】
原理:
Base64 使用US-ASCII子集的64个字符,即大小写的26个英文字母,0-9,+,/。
编码总是基于3个字符,每个字符用8位二进制表示,因此一共24位,再分为4四组,每组6位,表示一个Base64的值。如下:
"A", "B", "C", "D", "E", "F", "G", "H", "I","J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f",
"g", "h", "i","j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"
Base64值为0就是A,为27的就是b。这样,每3个字符产生4位的Base64字符。如果被加密的字符串每3个一组,还剩1或2个字符,使用特殊字符"="补齐Base64的4字。
如,编码只有2个字符“me”,m的ascii是109,e的是101,用二进制表示分别是01101101、01100101,连接起来就是 0110110101100101,再按6位分为一组:011011、010110、010100(不足6位补0),分别ascii分别是27、22、 20,即Base64值为bWU,Base64不足4字,用=补齐,因此bWU=就me的Base64值。
Base64算法将输入的字符串或一段数据编码成只含有{''A''-''Z'', ''a''-''z'', ''0''-''9'', ''+'', ''/''}这64个字符的串,''=''用于填充。其编码的方法是,将输入数据流每次取6 bit,用此6 bit的值(0-63)作为索引去查表,输出相应字符。这样,每3个字节将编码为4个字符(3×8 → 4×6);不满4个字符的以''=''填充。
编码的过程是这样的:
第一个字符通过右移2位获得第一个目标字符的Base64表位置,根据这个数值取到表上相应的字符,就是第一个目标字符。
然后将第一个字符左移4位加上第二个字符右移4位,即获得第二个目标字符。
再将第二个字符左移2位加上第三个字符右移6位,获得第三个目标字符。
最后取第三个字符的右6位即获得第四个目标字符。
在以上的每一个步骤之后,再把结果与 0x3F 进行 AND 位操作,就可以得到编码后的字符了。
--------------------------------------------------------------------------------
【注册验证部分代码】
首先输入假注信息
用户名:tgfy
注册码:1234
00412AC2 > \68 FF000000 PUSH 0FF ; /Count = FF (255.); Case 3EA of switch 00412AA8
00412AC7 . 68 F0334100 PUSH Base64Cr.004133F0 ; |Buffer = Base64Cr.004133F0
00412ACC . 68 F2030000 PUSH 3F2 ; |ControlID = 3F2 (1010.)
00412AD1 . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412AD4 . 50 PUSH EAX ; |hWnd
00412AD5 . E8 AE2CFFFF CALL <JMP.&user32.GetDlgItemTextA> ; \GetDlgItemTextA
00412ADA . 8D45 B4 LEA EAX,DWORD PTR SS:[EBP-4C] ; 根据字符串参考在这里下断
00412ADD . BA F0334100 MOV EDX,Base64Cr.004133F0 ; ASCII "tgfy"
00412AE2 . B9 FF000000 MOV ECX,0FF
00412AE7 . E8 9810FFFF CALL Base64Cr.00403B84
00412AEC . 837D B4 00 CMP DWORD PTR SS:[EBP-4C],0 ; 用户名不能为空
00412AF0 . 75 1C JNZ SHORT Base64Cr.00412B0E
00412AF2 . 6A 40 PUSH 40 ; /Style = MB_OK|MB_ICONASTERISK|MB_APPLMODAL
00412AF4 . 68 282D4100 PUSH Base64Cr.00412D28 ; |注册提示
00412AF9 . 68 342D4100 PUSH Base64Cr.00412D34 ; |用户名不能为空请输入!
00412AFE . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412B01 . 50 PUSH EAX ; |hOwner
00412B02 . E8 B92CFFFF CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA
00412B07 . 33DB XOR EBX,EBX
00412B09 . E9 A2010000 JMP Base64Cr.00412CB0
00412B0E > 68 FF000000 PUSH 0FF ; /Count = FF (255.)
00412B13 . 68 F0344100 PUSH Base64Cr.004134F0 ; |Buffer = Base64Cr.004134F0
00412B18 . 68 F3030000 PUSH 3F3 ; |ControlID = 3F3 (1011.)
00412B1D . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412B20 . 50 PUSH EAX ; |hWnd
00412B21 . E8 622CFFFF CALL <JMP.&user32.GetDlgItemTextA> ; \GetDlgItemTextA
00412B26 . 8D45 B0 LEA EAX,DWORD PTR SS:[EBP-50]
00412B29 . BA F0344100 MOV EDX,Base64Cr.004134F0
00412B2E . B9 FF000000 MOV ECX,0FF
00412B33 . E8 4C10FFFF CALL Base64Cr.00403B84
00412B38 . 837D B0 00 CMP DWORD PTR SS:[EBP-50],0 ; 注册码不能为空
00412B3C . 75 1C JNZ SHORT Base64Cr.00412B5A
00412B3E . 6A 40 PUSH 40 ; /Style = MB_OK|MB_ICONASTERISK|MB_APPLMODAL
00412B40 . 68 282D4100 PUSH Base64Cr.00412D28 ; |注册提示
00412B45 . 68 4C2D4100 PUSH Base64Cr.00412D4C ; |注册码不能为空请输入!
00412B4A . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412B4D . 50 PUSH EAX ; |hOwner
00412B4E . E8 6D2CFFFF CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA
00412B53 . 33DB XOR EBX,EBX
00412B55 . E9 56010000 JMP Base64Cr.00412CB0
00412B5A > 33C0 XOR EAX,EAX
00412B5C . 55 PUSH EBP
00412B5D . 68 DC2B4100 PUSH Base64Cr.00412BDC
00412B62 . 64:FF30 PUSH DWORD PTR FS:[EAX]
00412B65 . 64:8920 MOV DWORD PTR FS:[EAX],ESP
00412B68 . 8D45 AC LEA EAX,DWORD PTR SS:[EBP-54]
00412B6B . BA F0334100 MOV EDX,Base64Cr.004133F0 ; ASCII "tgfy"
00412B70 . B9 FF000000 MOV ECX,0FF
00412B75 . E8 0A10FFFF CALL Base64Cr.00403B84
00412B7A . 8B45 AC MOV EAX,DWORD PTR SS:[EBP-54]
00412B7D . 50 PUSH EAX
00412B7E . 8D45 A4 LEA EAX,DWORD PTR SS:[EBP-5C]
00412B81 . BA F0344100 MOV EDX,Base64Cr.004134F0
00412B86 . B9 FF000000 MOV ECX,0FF
00412B8B . E8 F40FFFFF CALL Base64Cr.00403B84
00412B90 . 8B45 A4 MOV EAX,DWORD PTR SS:[EBP-5C]
00412B93 . 8D55 A8 LEA EDX,DWORD PTR SS:[EBP-58]
00412B96 . E8 E5F8FFFF CALL Base64Cr.00412480 ; 算法Call
00412B9B . 8B55 A8 MOV EDX,DWORD PTR SS:[EBP-58]
00412B9E . 58 POP EAX
00412B9F . E8 5811FFFF CALL Base64Cr.00403CFC ; 比较Call
00412BA4 . 75 17 JNZ SHORT Base64Cr.00412BBD
00412BA6 . 6A 40 PUSH 40 ; /Style = MB_OK|MB_ICONASTERISK|MB_APPLMODAL
00412BA8 . 68 282D4100 PUSH Base64Cr.00412D28 ; |注册提示
00412BAD . 68 642D4100 PUSH Base64Cr.00412D64 ; |恭喜您,注册码正确!
00412BB2 . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412BB5 . 50 PUSH EAX ; |hOwner
00412BB6 . E8 052CFFFF CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA
00412BBB . EB 15 JMP SHORT Base64Cr.00412BD2
00412BBD > 6A 40 PUSH 40 ; /Style = MB_OK|MB_ICONASTERISK|MB_APPLMODAL
00412BBF . 68 282D4100 PUSH Base64Cr.00412D28 ; |注册提示
00412BC4 . 68 7C2D4100 PUSH Base64Cr.00412D7C ; |注册码错误,继续加油!
00412BC9 . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412BCC . 50 PUSH EAX ; |hOwner
00412BCD . E8 EE2BFFFF CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA
00412BD2 > 33C0 XOR EAX,EAX
00412BD4 . 5A POP EDX
00412BD5 . 59 POP ECX
00412BD6 . 59 POP ECX
00412BD7 . 64:8910 MOV DWORD PTR FS:[EAX],EDX
00412BDA . EB 39 JMP SHORT Base64Cr.00412C15
00412BDC .^ E9 2F06FFFF JMP Base64Cr.00403210
00412BE1 . 6A 40 PUSH 40 ; /Style = MB_OK|MB_ICONASTERISK|MB_APPLMODAL
00412BE3 . 68 282D4100 PUSH Base64Cr.00412D28 ; |注册提示
00412BE8 . 68 7C2D4100 PUSH Base64Cr.00412D7C ; |注册码错误,继续加油!
00412BED . 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8] ; |
00412BF0 . 50 PUSH EAX ; |hOwner
00412BF1 . E8 CA2BFFFF CALL <JMP.&user32.MessageBoxA> ; \MessageBoxA
00412BF6 . E8 F507FFFF CALL Base64Cr.004033F0
【关键算法Call】
00412480 /$ 53 PUSH EBX
00412481 |. 56 PUSH ESI
00412482 |. 57 PUSH EDI
00412483 |. 51 PUSH ECX
00412484 |. 891424 MOV DWORD PTR SS:[ESP],EDX
00412487 |. 8BF8 MOV EDI,EAX ; 注册码
00412489 |. B2 01 MOV DL,1
0041248B |. A1 70F44000 MOV EAX,DWORD PTR DS:[40F470]
00412490 |. E8 9B09FFFF CALL Base64Cr.00402E30
00412495 |. 8BF0 MOV ESI,EAX
00412497 |. B2 01 MOV DL,1
00412499 |. A1 70F44000 MOV EAX,DWORD PTR DS:[40F470]
0041249E |. E8 8D09FFFF CALL Base64Cr.00402E30
004124A3 |. 8BD8 MOV EBX,EAX
004124A5 |. 8BC7 MOV EAX,EDI
004124A7 |. E8 0417FFFF CALL Base64Cr.00403BB0
004124AC |. 50 PUSH EAX
004124AD |. 8BC7 MOV EAX,EDI
004124AF |. E8 EC18FFFF CALL Base64Cr.00403DA0
004124B4 |. 8BD0 MOV EDX,EAX
004124B6 |. 8BC6 MOV EAX,ESI
004124B8 |. 59 POP ECX
004124B9 |. 8B38 MOV EDI,DWORD PTR DS:[EAX]
004124BB |. FF57 10 CALL DWORD PTR DS:[EDI+10]
004124BE |. 6A 00 PUSH 0 ; /Arg2 = 00000000
004124C0 |. 6A 00 PUSH 0 ; |Arg1 = 00000000
004124C2 |. 8BC6 MOV EAX,ESI ; |
004124C4 |. E8 B7ECFFFF CALL Base64Cr.00411180 ; \Base64Cr.00411180
004124C9 |. 8BD3 MOV EDX,EBX
004124CB |. 8BC6 MOV EAX,ESI
004124CD |. E8 0AFEFFFF CALL Base64Cr.004122DC ; 核心算法Call
004124D2 |. 6A 00 PUSH 0 ; /Arg2 = 00000000
004124D4 |. 6A 00 PUSH 0 ; |Arg1 = 00000000
004124D6 |. 8BC3 MOV EAX,EBX ; |
004124D8 |. E8 A3ECFFFF CALL Base64Cr.00411180 ; \Base64Cr.00411180
004124DD |. 8BC3 MOV EAX,EBX
004124DF |. 8B10 MOV EDX,DWORD PTR DS:[EAX]
004124E1 |. FF12 CALL DWORD PTR DS:[EDX]
004124E3 |. 8BD0 MOV EDX,EAX
004124E5 |. 8B0424 MOV EAX,DWORD PTR SS:[ESP]
004124E8 |. E8 9319FFFF CALL Base64Cr.00403E80
004124ED |. 8BC3 MOV EAX,EBX
004124EF |. 8B10 MOV EDX,DWORD PTR DS:[EAX]
004124F1 |. FF12 CALL DWORD PTR DS:[EDX]
004124F3 |. 50 PUSH EAX
004124F4 |. 8B4424 04 MOV EAX,DWORD PTR SS:[ESP+4]
004124F8 |. E8 F318FFFF CALL Base64Cr.00403DF0
004124FD |. 8BD0 MOV EDX,EAX
004124FF |. 8BC3 MOV EAX,EBX
00412501 |. 59 POP ECX
00412502 |. 8B38 MOV EDI,DWORD PTR DS:[EAX]
00412504 |. FF57 0C CALL DWORD PTR DS:[EDI+C]
00412507 |. 8BC6 MOV EAX,ESI
00412509 |. E8 5209FFFF CALL Base64Cr.00402E60
0041250E |. 8BC3 MOV EAX,EBX
00412510 |. E8 4B09FFFF CALL Base64Cr.00402E60
00412515 |. 5A POP EDX
00412516 |. 5F POP EDI
00412517 |. 5E POP ESI
00412518 |. 5B POP EBX
00412519 \. C3 RET
【核心算法Call】
004122DC /$ 53 PUSH EBX ; 关键算法处
004122DD |. 56 PUSH ESI
004122DE |. 57 PUSH EDI
004122DF |. 81C4 58FFFFFF ADD ESP,-0A8
004122E5 |. 895424 04 MOV DWORD PTR SS:[ESP+4],EDX
004122E9 |. 890424 MOV DWORD PTR SS:[ESP],EAX
004122EC |. 8D7424 0C LEA ESI,DWORD PTR SS:[ESP+C]
004122F0 |> C64424 08 00 /MOV BYTE PTR SS:[ESP+8],0
004122F5 |. 33DB |XOR EBX,EBX
004122F7 |. 8BD6 |MOV EDX,ESI
004122F9 |. B9 58000000 |MOV ECX,58
004122FE |. 8B0424 |MOV EAX,DWORD PTR SS:[ESP]
00412301 |. 8B38 |MOV EDI,DWORD PTR DS:[EAX]
00412303 |. FF57 0C |CALL DWORD PTR DS:[EDI+C] ; EAX=注册码位数
00412306 |. 884424 09 |MOV BYTE PTR SS:[ESP+9],AL
0041230A |. 807C24 09 00 |CMP BYTE PTR SS:[ESP+9],0 ; 注册码位数与0比较
0041230F |. 0F84 3C010000 |JE Base64Cr.00412451 ; 等于跳
00412315 |. 3A5C24 09 |CMP BL,BYTE PTR SS:[ESP+9]
00412319 |. 0F83 10010000 |JNB Base64Cr.0041242F ; 大于等于跳
0041231F |> 33D2 |/XOR EDX,EDX
00412321 |. 8AD3 ||MOV DL,BL
00412323 |. 8A0416 ||MOV AL,BYTE PTR DS:[ESI+EDX] ; 依次取注册码1
00412326 |. 3C 2B ||CMP AL,2B
00412328 |. 72 46 ||JB SHORT Base64Cr.00412370
0041232A |. 3C 7A ||CMP AL,7A
0041232C |. 77 42 ||JA SHORT Base64Cr.00412370
0041232E |. 33C0 ||XOR EAX,EAX
00412330 |. 8AC3 ||MOV AL,BL
00412332 |. 807C06 01 2B ||CMP BYTE PTR DS:[ESI+EAX+1],2B ; 依次取注册码2
00412337 |. 72 37 ||JB SHORT Base64Cr.00412370
00412339 |. 33C0 ||XOR EAX,EAX
0041233B |. 8AC3 ||MOV AL,BL
0041233D |. 807C06 01 7A ||CMP BYTE PTR DS:[ESI+EAX+1],7A
00412342 |. 77 2C ||JA SHORT Base64Cr.00412370
00412344 |. 33C0 ||XOR EAX,EAX
00412346 |. 8AC3 ||MOV AL,BL
00412348 |. 807C06 02 2B ||CMP BYTE PTR DS:[ESI+EAX+2],2B ; 依次取注册码3
0041234D |. 72 21 ||JB SHORT Base64Cr.00412370
0041234F |. 33C0 ||XOR EAX,EAX
00412351 |. 8AC3 ||MOV AL,BL
00412353 |. 807C06 02 7A ||CMP BYTE PTR DS:[ESI+EAX+2],7A
00412358 |. 77 16 ||JA SHORT Base64Cr.00412370
0041235A |. 33C0 ||XOR EAX,EAX
0041235C |. 8AC3 ||MOV AL,BL
0041235E |. 807C06 03 2B ||CMP BYTE PTR DS:[ESI+EAX+3],2B ; 依次取注册码4
00412363 |. 72 0B ||JB SHORT Base64Cr.00412370 ; 小于则跳
00412365 |. 33C0 ||XOR EAX,EAX
00412367 |. 8AC3 ||MOV AL,BL
00412369 |. 807C06 03 7A ||CMP BYTE PTR DS:[ESI+EAX+3],7A
0041236E |. 76 16 ||JBE SHORT Base64Cr.00412386 ; 小于跳走,这里跳走
00412370 |> B9 64244100 ||MOV ECX,Base64Cr.00412464 ; invalid base64 character
00412375 |. B2 01 ||MOV DL,1
00412377 |. A1 FC5B4000 ||MOV EAX,DWORD PTR DS:[405BFC]
0041237C |. E8 0F7AFFFF ||CALL Base64Cr.00409D90
00412381 |. E8 EE0FFFFF ||CALL Base64Cr.00403374
00412386 |> 33C0 ||XOR EAX,EAX
00412388 |. 8A0416 ||MOV AL,BYTE PTR DS:[ESI+EDX] ; 依次取注册码1
0041238B |. 8A80 71334100 ||MOV AL,BYTE PTR DS:[EAX+413371] ; 根据字符ASCII码查表
00412391 |. 884424 0A ||MOV BYTE PTR SS:[ESP+A],AL ; 这里存入查表值m1
00412395 |. 8BFB ||MOV EDI,EBX ; EBX=0
00412397 |. 81E7 FF000000 ||AND EDI,0FF
0041239D |. 33C0 ||XOR EAX,EAX
0041239F |. 8A443E 01 ||MOV AL,BYTE PTR DS:[ESI+EDI+1] ; 依次取注册码2
004123A3 |. 8A80 71334100 ||MOV AL,BYTE PTR DS:[EAX+413371] ; 查表值m2
004123A9 |. 33D2 ||XOR EDX,EDX
004123AB |. 8A543E 02 ||MOV DL,BYTE PTR DS:[ESI+EDI+2] ; 依次取注册码3
004123AF |. 8A92 71334100 ||MOV DL,BYTE PTR DS:[EDX+413371]
004123B5 |. 885424 0B ||MOV BYTE PTR SS:[ESP+B],DL ; 这里存入查表值m3
004123B9 |. 8A5424 0A ||MOV DL,BYTE PTR SS:[ESP+A] ; 取值m1
004123BD |. C1E2 02 ||SHL EDX,2 ; m1<<2
004123C0 |. 33C9 ||XOR ECX,ECX
004123C2 |. 8AC8 ||MOV CL,AL ; m2
004123C4 |. C1E9 04 ||SHR ECX,4 ; m2>>4
004123C7 |. 0AD1 ||OR DL,CL ; m1|m2
004123C9 |. 33C9 ||XOR ECX,ECX
004123CB |. 8A4C24 08 ||MOV CL,BYTE PTR SS:[ESP+8]
004123CF |. 88540C 64 ||MOV BYTE PTR SS:[ESP+ECX+64],DL ; a1
004123D3 |. FE4424 08 ||INC BYTE PTR SS:[ESP+8]
004123D7 |. 807C3E 02 3D ||CMP BYTE PTR DS:[ESI+EDI+2],3D ; 第3位不能为字符'='
004123DC |. 74 44 ||JE SHORT Base64Cr.00412422
004123DE |. C1E0 04 ||SHL EAX,4 ; m2<<4
004123E1 |. 33D2 ||XOR EDX,EDX
004123E3 |. 8A5424 0B ||MOV DL,BYTE PTR SS:[ESP+B] ; m3
004123E7 |. C1EA 02 ||SHR EDX,2 ; m3>>2
004123EA |. 0AC2 ||OR AL,DL ; m2|m3
004123EC |. 33D2 ||XOR EDX,EDX
004123EE |. 8A5424 08 ||MOV DL,BYTE PTR SS:[ESP+8]
004123F2 |. 884414 64 ||MOV BYTE PTR SS:[ESP+EDX+64],AL ; a2
004123F6 |. FE4424 08 ||INC BYTE PTR SS:[ESP+8]
004123FA |. 807C3E 03 3D ||CMP BYTE PTR DS:[ESI+EDI+3],3D ; 第4位不能为字符'='
004123FF |. 74 21 ||JE SHORT Base64Cr.00412422
00412401 |. 8A4424 0B ||MOV AL,BYTE PTR SS:[ESP+B] ; m3
00412405 |. C1E0 06 ||SHL EAX,6
00412408 |. 33D2 ||XOR EDX,EDX
0041240A |. 8A543E 03 ||MOV DL,BYTE PTR DS:[ESI+EDI+3] ; m4
0041240E |. 0A82 71334100 ||OR AL,BYTE PTR DS:[EDX+413371]
00412414 |. 33D2 ||XOR EDX,EDX
00412416 |. 8A5424 08 ||MOV DL,BYTE PTR SS:[ESP+8]
0041241A |. 884414 64 ||MOV BYTE PTR SS:[ESP+EDX+64],AL ; a3
0041241E |. FE4424 08 ||INC BYTE PTR SS:[ESP+8]
00412422 |> 80C3 04 ||ADD BL,4
00412425 |. 3A5C24 09 ||CMP BL,BYTE PTR SS:[ESP+9] ; 注册码是否参与完毕
00412429 |.^ 0F82 F0FEFFFF |\JB Base64Cr.0041231F
0041242F |> 33C9 |XOR ECX,ECX
00412431 |. 8A4C24 08 |MOV CL,BYTE PTR SS:[ESP+8]
00412435 |. 8D5424 64 |LEA EDX,DWORD PTR SS:[ESP+64]
00412439 |. 8B4424 04 |MOV EAX,DWORD PTR SS:[ESP+4]
0041243D |. 8B18 |MOV EBX,DWORD PTR DS:[EAX]
0041243F |. FF53 10 |CALL DWORD PTR DS:[EBX+10]
00412442 |. 33C0 |XOR EAX,EAX
00412444 |. 8A4424 09 |MOV AL,BYTE PTR SS:[ESP+9]
00412448 |. 83F8 58 |CMP EAX,58
0041244B |.^ 0F83 9FFEFFFF \JNB Base64Cr.004122F0
00412451 |> 81C4 A8000000 ADD ESP,0A8
00412457 |. 5F POP EDI
00412458 |. 5E POP ESI
00412459 |. 5B POP EBX
0041245A \. C3 RET
--------------------------------------------------------------------------------
【算法小结】
1、这是一个变形的Base64加密算法,其使用的字符集如下:
0041339C 3E 7F 7F 7F 3F 34 35 36 37 38 39 3A 3B 3C 3D 7F >?456789:;<=
004133AC 7F 7F 7F 7F 7F 7F 00 01 02 03 04 05 06 07 08 09 ..
004133BC 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 ...
004133CC 7F 7F 7F 7F 7F 7F 1A 1B 1C 1D 1E 1F 20 21 22 23 !"#
004133DC 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 $%&'()*+,-./0123
一共使用了80个。
2、提供处理的字符(注册码处可输入字符的ASCII码为2B("+")到7A("z")),且注册码输入必须是4位数的倍数。
3、处理过程:
(1)按4位字符一组,通过计算每个输入字符的ASCII码值查上述的码表值,依次记为n1,n2,n3,n4...
(2)将上述所查的值按m1=n1<<0x2,m2=n2>>0x4,a1=m1|m2
m2=n2<<0x4,m3=n3>>0x2,a2=m2|m3
m3=n3<<0x6,m4=n4, a3=m3|m4
进行上述变换,即每4个字符变换成3个新字符(8个字符变换成6个新字符,依次类推)。
4、最后变换的新字符与用户名比较,看是否一致即可。
--------------------------------------------------------------------------------
【C语言注册机】
#include "stdio.h"
#include "string.h"
//自定义函数//
void fun1(char sn[30],char *p_base,char *p_resu);
//主函数
void main()
{
int i,l;
char sn[30];//注册码(必须是4位数的倍数)
/*
0041339C 3E 7F 7F 7F 3F 34 35 36 37 38 39 3A 3B 3C 3D 7F >?456789:;<=
004133AC 7F 7F 7F 7F 7F 7F 00 01 02 03 04 05 06 07 08 09 ..........
004133BC 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 ...............
004133CC 7F 7F 7F 7F 7F 7F 1A 1B 1C 1D 1E 1F 20 21 22 23 ...... !"#
004133DC 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 $%&'()*+,-./0123
*/
char base64_alphabet[80]=
{0x3e,0x7f,0x7f,0x7f,0x3f,'4','5','6','7','8','9',':',';','<','=', 0x7f,
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,
0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,
0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,'0','1','2','3'};
char result[256]={0};//输出结果
char *p_base,*p_resu;
p_base=base64_alphabet;
p_resu=result;
printf("请输入注册码(必须是4位数的倍数): ");
gets(sn);
fun1(sn,p_base,p_resu);//调用fun1函数得到注册码
printf("\n");
printf("你的注册码是: ");
l=strlen(result);
for(i=0;i<l;i++)
printf("%c",result[i]);
printf("\n");
for(i=0;i<l;i++)
{
printf("%x",result[i]);
printf("\n");
}
printf("\n");
}
//调用自定义函数
void fun1(char sn[30],char *p_base,char *p_resu)
{
int i,j=0,l;
int m1,m2,m3,m4,n1,n2,n3,n4;
l=strlen(sn);
for(i=0;i<l;i=i+4)//注册码位数大于4的1倍以上开始循环
{
n1=*(p_base+(sn[i+0]-0x2b));
n2=*(p_base+(sn[i+1]-0x2b));
n3=*(p_base+(sn[i+2]-0x2b));
n4=*(p_base+(sn[i+3]-0x2b));
m1=n1<<0x2;
m2=n2>>0x4;
*(p_resu+j)=(m1&0xff)|(m2&0xff);//保证低字节参与运算
m2=n2<<0x4;
m3=n3>>0x2;
*(p_resu+j+1)=(m2&0xff)|(m3&0xff);
m3=n3<<0x6;
m4=n4;
*(p_resu+j+2)=(m3&0xff)|(m4&0xff);
j=j+3;
}
}
一组可用的奇怪注册码:
用户名:邁t
注册码:3350
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)