EncryptService.pas 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. unit EncryptService;
  2. interface
  3. uses Classes, TypeUnit, SysUtils;
  4. type
  5. {加密发送的数据}
  6. TScEncryptService = class
  7. private
  8. function EncryptInteger(Value: Integer): string;
  9. function DeEncryptInteger(Value: string): Integer;
  10. public
  11. {服务数据加密}
  12. function EncryptString(const Value: string): string;
  13. {解密客户数据 IP + 版本类型 + Action}
  14. function DeEncryptString(const Value: string; AInfoRec: PInfoRecd): string;
  15. end;
  16. implementation
  17. { TScEncryptService }
  18. function TScEncryptService.DeEncryptInteger(Value: string): Integer;
  19. begin
  20. end;
  21. function TScEncryptService.DeEncryptString(const Value: string; AInfoRec: PInfoRecd): string;
  22. var
  23. sText: string;
  24. iLen: Integer;
  25. begin
  26. if SameText(Value, '') then
  27. begin
  28. AInfoRec.Action := -1;
  29. Exit;
  30. end;
  31. sText := Copy(Value, 2, 2);
  32. iLen := StrToInt(sText);
  33. AInfoRec^.IP := Copy(Value, 5, iLen);
  34. sText := Copy(Value, 21, 2);
  35. AInfoRec^.User := StrToInt(sText);
  36. sText := Copy(Value, 23, 1);
  37. AInfoRec.Action := StrToInt(sText);
  38. end;
  39. function TScEncryptService.EncryptInteger(Value: Integer): string;
  40. begin
  41. end;
  42. function TScEncryptService.EncryptString(const Value: string): string;
  43. var
  44. I, iValue: Integer;
  45. begin
  46. Randomize;
  47. SetLength(Result, Length(Value) + 5);
  48. iValue := Random(26) + 65;
  49. Result[1] := Chr(iValue);
  50. iValue := Random(26) + 65;
  51. Result[2] := Chr(iValue);
  52. iValue := Random(26) + 65;
  53. Result[3] := Chr(iValue);
  54. for I := 1 to Length(Value) do
  55. begin
  56. Result[I + 3] := Value[I];
  57. end;
  58. I := 3 + Length(Value);
  59. iValue := Random(26) + 65;
  60. Result[I + 1] := Chr(iValue);
  61. iValue := Random(26) + 65;
  62. Result[I + 2] := Chr(iValue);
  63. end;
  64. end.