004DAED4   55                     push    ebp
004DAED5   8BEC                   mov     ebp, esp
004DAED7   83C4E8                 add     esp, -$18
004DAEDA   53                     push    ebx
004DAEDB   56                     push    esi
004DAEDC   57                     push    edi
004DAEDD   33C9                   xor     ecx, ecx
004DAEDF   894DEC                 mov     [ebp-$14], ecx
004DAEE2   894DE8                 mov     [ebp-$18], ecx
004DAEE5   894DF4                 mov     [ebp-$0C], ecx
004DAEE8   8BFA                   mov     edi, edx { 加密之后的输出结果 } 
004DAEEA   8945FC                 mov     [ebp-$04], eax { CardID; 6个字符 } 
004DAEED   33C0                   xor     eax, eax
004DAEEF   55                     push    ebp* Possible String Reference to: '榇愹脬_^[嬪]脥@'
|
004DAEF0   68BFAF4D00             push    $004DAFBF***** TRY
|
004DAEF5   64FF30                 push    dword ptr fs:[eax]
004DAEF8   648920                 mov     fs:[eax], esp
004DAEFB   8D45F4                 lea     eax, [ebp-$0C]* Reference to: System.@LStrClr(void;void);
|
004DAEFE   E8B198F2FF             call    004047B4 { 清空 [ebp-$0C] } 
004DAF03   66C745FA1245           mov     word ptr [ebp-$06], $4512 { 加密整数因子; 加密因子赋值 } 
004DAF09   8BC7                   mov     eax, edi
004DAF0B   8B55FC                 mov     edx, [ebp-$04] { CardID;  } * Reference to: System.@LStrAsg(void;void;void;void);
|
004DAF0E   E8F598F2FF             call    00404808 { 用原始卡号填充本过程的返回结果 } 
004DAF13   8B45FC                 mov     eax, [ebp-$04] { CardID;  } * Reference to: System.@LStrLen(String):Integer;
|           or: System.@DynArrayLength;
|           or: System.DynArraySize(Pointer):Integer;
|
004DAF16   E8519BF2FF             call    00404A6C
004DAF1B   84C0                   test    al, al { CardID 长度 } 
004DAF1D   7673                   jbe     004DAF92
004DAF1F   8845F3                 mov     [ebp-$0D], al 
004DAF22   B301                   mov     bl, $01 { 循环变量赋初值 } 
004DAF24   8BC7                   mov     eax, edi { 本过程的返回结果 } * Reference to: System.FPower10;
|           or: System.UniqueString(String;String);overload;
|           or: System.@UniqueStringA(String;String);
|           or: System.@WStrLAsg(WideString;WideString;WideString);
|           or: System.FinalizeArray(Pointer;Pointer;Integer);
|
004DAF26   E8919DF2FF             call    00404CBC { 类似 Pchar=@String } 
004DAF2B   8BF3                   mov     esi, ebx { 循环计数,每次加1 } 
004DAF2D   81E6FF000000           and     esi, $000000FF { 去掉高位 } 
004DAF33   8B55FC                 mov     edx, [ebp-$04] { CardID;  } 
004DAF36   8A5432FF               mov     dl, byte ptr [edx+esi-$01] { 取卡号的第esi个字符 } 
004DAF3A   0FB74DFA               movzx   ecx, word ptr [ebp-$06] { 加密整数因子; $4512;17682 } 
004DAF3E   C1E908                 shr     ecx, $08 { 右移8位 } 
004DAF41   32D1                   xor     dl, cl { 与卡号的第esi个字与或 } 
004DAF43   885430FF               mov     [eax+esi-$01], dl { 保存结果 } 
004DAF47   8D45EC                 lea     eax, [ebp-$14] { [ebp-14] 压栈 } 
004DAF4A   50                     push    eax
004DAF4B   8B07                   mov     eax, [edi]
004DAF4D   0FB64430FF             movzx   eax, byte ptr [eax+esi-$01] { 取出结果 } 
004DAF52   8D55E8                 lea     edx, [ebp-$18]* Reference to: Unit_00408298.Proc_00409398
|
004DAF55   E83EE4F2FF             call    00409398 { Format String }
004DAF5A   8B45E8                 mov     eax, [ebp-$18] { %d格式化后的字符串 } 
004DAF5D   B130                   mov     cl, $30
004DAF5F   BA03000000             mov     edx, $00000003* Reference to: Unit_005B0F50.Proc_005B134C
|
004DAF64   E8E3630D00             call    005B134C { 格式化成3位的字符串,不足在前面补'0' } 
004DAF69   8B55EC                 mov     edx, [ebp-$14] { 输出的结果 } 
004DAF6C   8D45F4                 lea     eax, [ebp-$0C]* Reference to: System.@LStrCat;
|
004DAF6F   E8009BF2FF             call    00404A74 { 连接每次输出的结果,保存在[ebp-$0C]中 } 
004DAF74   8B07                   mov     eax, [edi]
004DAF76   0FB64430FF             movzx   eax, byte ptr [eax+esi-$01]
004DAF7B   660345FA               add     ax, word ptr [ebp-$06] { 加密整数因子; 17682 } 
004DAF7F   6669C05B7B             imul    ax, ax, $7B5B
004DAF84   6605A104               add     ax, +$04A1
004DAF88   668945FA               mov     [ebp-$06], ax { 加密整数因子; 更改 } 
004DAF8C   43                     inc     ebx
004DAF8D   FE4DF3                 dec     byte ptr [ebp-$0D] { CardIDLen; 里面存有原始卡号长度 } 
004DAF90   7592                   jnz     004DAF24
004DAF92   8BC7                   mov     eax, edi
004DAF94   8B55F4                 mov     edx, [ebp-$0C]* Reference to: System.@LStrAsg(void;void;void;void);
|
004DAF97   E86C98F2FF             call    00404808
004DAF9C   33C0                   xor     eax, eax
004DAF9E   5A                     pop     edx
004DAF9F   59                     pop     ecx
004DAFA0   59                     pop     ecx
004DAFA1   648910                 mov     fs:[eax], edx****** FINALLY
|* Possible String Reference to: '_^[嬪]脥@'
|
004DAFA4   68C6AF4D00             push    $004DAFC6
004DAFA9   8D45E8                 lea     eax, [ebp-$18]
004DAFAC   BA02000000             mov     edx, $00000002* Reference to: System.@LStrArrayClr(void;void;Integer);
|
004DAFB1   E82298F2FF             call    004047D8
004DAFB6   8D45F4                 lea     eax, [ebp-$0C]* Reference to: System.@LStrClr(void;void);
|
004DAFB9   E8F697F2FF             call    004047B4
004DAFBE   C3                     ret
* Reference to: System.@HandleFinally;
|
004DAFBF   E9B490F2FF             jmp     00404078
004DAFC4   EBE3                   jmp     004DAFA9****** END
|
004DAFC6   5F                     pop     edi
004DAFC7   5E                     pop     esi
004DAFC8   5B                     pop     ebx
004DAFC9   8BE5                   mov     esp, ebp
004DAFCB   5D                     pop     ebp
004DAFCC   C3                     ret本人初学汇编,不知错在那里 下面是Delphi的翻译procedure TForm1.Button2Click(Sender: TObject);
var
    c,c0,c1,c2:integer;
    sCardNo:String;
    cardNoLen:integer;
    i:integer;
    tmpStr:string;
    s:string;
begin
   i:=1;
   c0:=$4512;
   sCardNo:='040648';//测试用的卡号
   cardNoLen:=Length(sCardNo);
   while  i <= CardNoLen do
   begin
      c2:=c0 shr $08;
      c1:=ord(sCardNo[i]);
      c:= c1 xor c2;
      tmpStr:=format('%d',[c]);
      if Length(tmpStr)>3 then
        tmpStr:=MidStr(tmpStr,1,3)
      else
        while(length(tmpStr)<3) do
          tmpStr:=chr($30)+ tmpStr;
      s:=s + tmpStr;
      c0:=c0 + c1;
      c0:=c0 * $7B5B;
      c0:=c0 + $04A1;
      inc(i);
   end;
   showMessage(s);
end;

解决方案 »

  1.   

    反编译了一下自己写的代码觉得应该像这样才对,改正了一下不知对了没有?请高手解答...Procedure ConvertToCard(sCardNo:string;var card:string);
    var
        c0,c2,c1:Word;
        c,i,cardNoLen:Byte;
        tmpStr,s:string;
    begin
       i:=1;
       c0:=$4512;
       card:=sCardNo;
       cardNoLen:=Length(sCardNo);
       if cardNoLen>0 then
       begin
       while  i <= CardNoLen do
       begin
          c1:=ord(sCardNo[i]);         //第一次加密开始 :>0
          c2:=c0 shr $08;
          c:= Byte(c1) xor Byte(c2);   //---
          tmpStr:=IntToStr(c);         //转换为文本
          if Length(tmpStr)>3 then          //以下这六行 格式化为3个字符。
            tmpStr:=MidStr(tmpStr,1,3)
          else
            while(length(tmpStr)<3) do
              tmpStr:=chr($30)+ tmpStr;
          s:=s + tmpStr;               //连接每次产生的三个字符
          c0:=c0 + c;                  //第二次加密 :>)
          c0:=c0 * $7B5B;
          c0:=c0 + $04A1;              //----
          inc(i);
       end;
       card:=s;
       end;
    end;
      

  2.   

    Su_hibl,可以把这个解密函数发一下吗?