...
Code Block |
---|
|
function Encrypt(const InString:string; Salt:string): string;
var
i : Byte;
StartKey, MultKey, AddKey: Word;
begin
Result := '';
if (Salt = '') then begin
Result := InString;
end
else begin
StartKey := Length(Salt);
MultKey := Ord(Salt[1]);
AddKey := 0;
for i := 1 to Length(Salt) - 1 do AddKey := AddKey + Ord(Salt[i]);
for i := 1 to Length(InString) do
begin
Result := Result + CHAR(Byte(InString[i]) xor (StartKey shr 8));
StartKey := (Byte(Result[i]) + StartKey) * MultKey + AddKey;
end;
end;
end;
function Decrypt(const InString:string; Salt:string): string;
var
i : Byte;
StartKey, MultKey, AddKey: Word;
begin
Result := '';
if (Salt = '') then begin
Result := InString;
end
else begin
StartKey := Ord(Salt[1]);
MultKey := Length(Salt);
AddKey := 0;
for i := 1 to Length(Salt) - 1 do AddKey := AddKey + Ord(Salt[i]);
for i := 1 to Length(InString) do
begin
Result := Result + CHAR(Byte(InString[i]) xor (StartKey shr 8));
StartKey := (Byte(InString[i]) + StartKey) * MultKey + AddKey;
end;
end;
end;
|
ExampleBy the way, above was not helpful for me - I use multibyte character, and below code was so helpful even though I can't use any key on the documentation
Code Block |
---|
procedure TForm1.btn1Click(Sender: TObject);
begin
txt2.Text:= EncryptStr(txt1.Text, 223);
lbl1.Caption:= DecryptStr(txt2.Text, 223);
end; |
...
uses IdCoder, IdCoderMIME, IdGlobal;
..
..
begin
// encode string
sMasterXML.Text := TIdEncoderMIME.EncodeString(sMasterXML.Text, IndyTextEncoding_UTF8);
// deocde string
sMasterXML.Text := TIdDecoderMIME.DecodeString(sMasterXML.Text, IndyTextEncoding_UTF8);
end; |