可以取余数 n mod 255

解决方案 »

  1.   

    也是刚刚学的,哈哈
    const
      cKey = '随便你了';function Encrypt(mStr: string; mKey: string): string;
    var
      I, J: Integer;
    begin
      J := 1;
      Result := '';
      for I := 1 to Length(mStr) do begin
        Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
        if J + 1 <= Length(mKey) then
          Inc(J)
        else J := 1;
      end;
      {自己加步骤}
    end;function Decrypt(mStr: string; mKey: string): string;
    var
      I, J: Integer;
    begin
      J := 1;
      Result := '';
      {自己加步骤}
      for I := 1 to Length(mStr) do begin
        Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
        if J + 1 <= Length(mKey) then
          Inc(J)
        else J := 1;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Memo2.Text := Decrypt(Encrypt(Memo1.Text, cKey), cKey);
    end;
     
      

  2.   

    function f(mStr: string; mKey: string): string;
    var
      I, J: Integer;
    begin
      Result := '';
      J := 1;
      for I := 1 to Length(mStr) do begin
        Result := Result + Chr(Ord(mStr[I]) xor Ord(mKey[J]));
        if J + 1 < Length(mKey) then
          Inc(J)
        else J := 1;
      end;
    end;
      

  3.   

    为什么不用XOR,运算简单、可逆,且安全,微软也用,
    不存在超出255的问题!
      

  4.   

     z_x_b(狂龙)说的一点不错:我自己在做口令简单加密时就用的XOR
    为什么不用XOR,运算简单、可逆,且安全,微软也用,
    不存在超出255的问题! 
      

  5.   

    谢各位,XOR我也有用过,现在只是想讨论一下这个问题而已,而不是寻找有效的加密方法
    另:用XOR的话,能不能稍微复杂一点,而不仅仅只是安位异或,这样岂不是别人很容易进行反向解密?
      

  6.   

    mKey不一样!
    你还可以再用不同的mKey加密多次(只要你喜欢)
    密码当然都可以破
    可以不是不需要时间的
    他破一种的时间
    我可以玩出一百种加密出来
    看谁更麻烦
      

  7.   

    function Encrypt(mStr: string; mKey: string): string;
    var
      I, J: Integer;
    begin
      J := 1;
      Result := '';
      for I := 1 to Length(mStr) do begin
        Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
        if J + 1 <= Length(mKey) then
          Inc(J)
        else J := 1;
      end;
      {自己加步骤}
    end;function Decrypt(mStr: string; mKey: string): string;
    var
      I, J: Integer;
    begin
      J := 1;
      Result := '';
      {自己加步骤}
      for I := 1 to Length(mStr) do begin
        Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
        if J + 1 <= Length(mKey) then
          Inc(J)
        else J := 1;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    const
      cKey1 = '谁想试试怎么破';
      cKey2 = '我可不愿意这样玩(1)我可不愿意这样玩(2)我可不愿意这样玩(3)';
      cKey3 = 'Memo2.Text := Decrypt(Encrypt(Memo1.Text, cKey), cKey);';
    var
      S: string; //加密后的字符
    begin
      S := Encrypt(Encrypt(Encrypt(Memo1.Text, cKey1), cKey2), cKey3);
      ShowMessage(S);
      Memo2.Text := Decrypt(Decrypt(Decrypt(S, cKey3), cKey2), cKey1);
    end;
      

  8.   

    这种方法很好,可惜没给你提供完整代码:)
    逆运算也没给出实在对不起呵呵
    就算算法给破了也不太有问题。
    key1:=****;
    para1:=****;
    para2:=****;
    以上三个参数你自己记住就是了。
     resultStr:='';
           key1:=****;
           para1:=****;
           para2:=****;
                   //解密密钥
            for i:=1 to 9 do
              begin
                 Ch:=OriginStr[size-9+i];
                 Result:=char(byte(Ch)xor(key1 shr 8));
                 key1:=(byte(Ch)+key1)*para1+para2;             resultStr:=resultStr+Result;
              end;
      

  9.   

    看到没,key1一直在变依赖于前面的密文