要求:1,入口是一个数组,如array[1..400]  of  char  出口是一个数组如  array[1..400]  of  char  
2,每个字节先异或0x9f,然后高4位,低四位交换顺序。
3,入口参数array[1..400]  of  char如果400字节的空间只用了100字节,那么剩下的300字节初值也加密  
3,有加密和解密的算法。谢谢

解决方案 »

  1.   

    const DATA_SIZE=400;
    type
    TData=array[0..DATA_SIZE-1] of char;
    procedure Encrypt(var Input:TData;var Output:TData);
    asm
      mov ecx,DATA_SIZE
      mov esi,Input
      mov edi,Output
    @next:
      mov al,[esi+ecx-1]
      xor al,$9f
      rol al,4
      mov [edi+ecx-1],al
      loop @next
      ret
    end;
    procedure Decrypt(var Input:TData;var Output:TData);
    asm
      mov ecx,DATA_SIZE
      mov esi,Input
      mov edi,Output
    @next:
      mov al,[esi+ecx-1]
      rol al,4
      xor al,$9f
      mov [edi+ecx-1],al
      loop @next
      ret
    end;
      

  2.   

    其实是一样的。D没有对ROL,ROR的直接支持,高低四位换位有点麻烦:
    const DATA_SIZE=400;
    type
    TData=array[0..DATA_SIZE-1] of Char;
    procedure Encrypt(const Input:TData;var Output:TData);
    var i:Integer;C:Byte;
    begin
      for i:=Low(Input) to High(Input) do
      begin
        C:=Byte(Input[i]) xor $9f;
        Output[i]:=Char(((C and $f) shl 4) or (C shr 4));
      end;
    end;
    procedure Decrypt(const Input:TData;var Output:TData);
    var i:Integer;C:Byte;
    begin
      for i:=Low(Input) to High(Input) do
      begin
        C:=Byte(Input[i]);
        C:=((C and $f) shl 4) or (C shr 4);
        Output[i]:=Char(C xor $9f);
      end;
    end;
      

  3.   

    pfpf((C and $f) shl 4) or (C shr 4)
    这句写的好!