最好是讲解+数学算法。不要源代码。分不够可以另开帖子赠送。(我的级别低,一个问题只能赠100分)

解决方案 »

  1.   

    我这里有现成的资料,还有我实现的原代码,不过内容太多了。用Email发给你吧。
      

  2.   

    ////////Begin Source
    function EditVisibleText(mEdit: TEdit): string;
    var
      X, Y, L: Integer;
      S: string;
    begin
      Result := '';
      if not Assigned(mEdit) then Exit;
      with mEdit do try
        S := Text;
        L := Length(S);
        X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(2, 2));
        X := X and $0000FFFF;
        Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(ClientWidth - 4, 2));
        Y := Y and $0000FFFF;
        for X := X to Y - 1 do if (Y >= 0) and (X < L) then
          Result := Result + S[X + 1];
      except
        Result := '';
      end;
    end; { EditVisibleText }function MemoVisibleText(mMemo: TMemo; mStrings: TStrings): Boolean;
    var
      I, X, Y: Integer;
      L, H, W: Integer;
      S: string;
      T: string;
    begin
      Result := False;
      if (not Assigned(mMemo)) or (not Assigned(mStrings)) then Exit;
      with TControlCanvas.Create do try
        Control := mMemo;
        H := TextHeight('|');
      finally
        Free;
      end;
      mStrings.Clear;
      with mMemo do try
        S := Text;
        L := Length(S);
        W := ClientWidth;
        for I := 0 to (ClientHeight div H) - 1 do begin
          X := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(3, I * H + 2));
          X := X and $0000FFFF;
          Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(5, I * H + 2));
          Y := Y and $0000FFFF;
          if Abs(Y - X) > 1 then Inc(X);
          if not ((X = 0) or ((X < L) and (S[X - 1] in [#13, #10]))) then Inc(X);
          Y := SendMessage(Handle, EM_CHARFROMPOS, 0, MAKELPARAM(W - 2, I * H + 2));
          Y := Y and $0000FFFF;
          T := '';
          for X := X to Y - 1 do if (Y >= 0) and (X < L) then
            T := T + S[X + 1];
          mStrings.Add(T);
        end;
      except
        Exit;
      end;
      Result := True;
    end; { MemoVisibleText }
    ////////End Source////////Begin Demo
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      MemoVisibleText(Memo1, Memo2.Lines);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Caption := EditVisibleText(Edit1);
    end;
    ////////End Demo
    ///////Begin Source
    function StringToDisplay(mString: string): string;
    var
      I: Integer;
      S: string;
    begin
      Result := '';
      S := '';
      for I := 1 to Length(mString) do
        if mString[I] in [#32..#127] then
          S := S + mString[I]
        else begin
          if S <> '' then begin
            Result := Result + QuotedStr(S);
            S := '';
          end;
          Result := Result + Format('#$%x', [Ord(mString[I])]);
        end;
      if S <> '' then Result := Result + QuotedStr(S);
    end; { StringToDisplay }function DisplayToString(mDisplay: string): string;
    var
      I: Integer;
      S: string;
      B: Boolean;
    begin
      Result := '';
      B := False;
      mDisplay := mDisplay;
      for I := 1 to Length(mDisplay) do
        if B then case mDisplay[I] of
          '''': begin
            if S <> '' then Result := Result + StringReplace(S, '''''', '''', [rfReplaceAll]);
              if Copy(mDisplay, I + 1, 1) = '''' then Result := Result + '''';
              S := '';
              B := False;
            end;
          else S := S + mDisplay[I];
          end
        else case mDisplay[I] of
          '#', '''': begin
            if S <> '' then Result := Result + Chr(StrToIntDef(S, 0));
            S := '';
            B := mDisplay[I] = '''';
          end;
          '$', '0'..'9', 'a'..'f', 'A'..'F': S := S + mDisplay[I];
        end;
      if (not B) and (S <> '') then Result := Result + Chr(StrToIntDef(S, 0));
    end; { DisplayToString }function StringEncrypt(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; { StringEncrypt }function StringDecrypt(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; { StringDecrypt }
    ///////End Source///////Begin Demo
    const
      cKey = '给你这一把钥匙,只能打开这一把锁';procedure TForm1.Button1Click(Sender: TObject);
    begin
      Memo2.Text := StringToDisplay(StringEncrypt(Memo1.Text, cKey));
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Memo1.Text := StringDecrypt(DisplayToString(Memo2.Text), cKey);
    end;
    ///////End Demo
      

  3.   

    楼上的是什么啊?我怎么看都不象DES?
      

  4.   

    http://www.vckbase.com/sourcecode/algorithms/这里有DES算法,我载了看了,不错
    还有很多其他算法
      

  5.   

    终于找到我的资料来源了:
    http://www.yicard.com/cardtech/smartcard/jiami/6-1.htm