Jump to content


Photo

Encryption source code from Delphi to SMS

Delphi Encrypt Security

  • Please log in to reply
2 replies to this topic

#1 COMFIED

COMFIED
  • Members
  • 44 posts

Posted 30 June 2016 - 09:46 AM

I'm seeking help in making this Delphi code (from http://www.codeface.com.br/?p=1679) work in SmartMobileStudio.

 

 

function EncryptStr(const S: String; Key: Word): String;
var I: Integer;
const C1 = 53761;
      C2 = 32618;
begin
  Result := S;
  for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
    Key := (byte(Result[I]) + Key) * C1 + C2;
  end;
end;
 
function DecryptStr(const S: String; Key: Word): String;
var I: Integer;
const C1 = 53761;
      C2 = 32618;
begin
  Result := S;
  for I := 1 to Length(S) do begin
   Result[I] := char(byte(S[I]) xor (Key shr 8));
   Key := (byte(S[I]) + Key) * C1 + C2;
  end;
end;
 

 

 



#2 Laksekjønn

Laksekjønn
  • Members
  • 440 posts

Posted 30 June 2016 - 04:26 PM

Just a heads up: this approach doesn’t support Unicode characters. This function decryptStr returns the original string before it was encrypted. However, it returns some other weird characters altogether after decryption. 
 
const C1 = 53761;
const C2 = 32618;

function EncryptStr(const S: String; Key: Integer): String;
var I: Integer;
begin
  Result := S;
  for I := 1 to Length(S) do begin
    Result[I] := chr(ord(S[I]) xor (Key shr 8));
    Key := (ord(Result[I]) + Key) * C1 + C2;
  end;
end;

function DecryptStr(const S: String; Key: Integer): String;
var I: Integer;
begin
  Result := S;
  for I := 1 to Length(S) do begin
   Result[I] := chr(ord(S[I]) xor (Key shr 8));
   Key := (ord(S[I]) + Key) * C1 + C2;
  end;
end;
var str := EncryptStr('warleyalex', 2);  
WriteLn(str); // w掠⩨਒䙥yalex  --> w\u63A0\u2A68\u0A12\u4665yalex
WriteLn( DecryptStr(str, 2) ); //warleyalex
WriteLn( DecryptStr('w掠⩨਒䙥yalex', 2) ); //warleyalex
 

 

Another simpler version:

function EncryptStr(const S: String; Key: Integer): String;
var I: Integer;
    fuck: string;
begin
  for I := 1 to Length(S) do begin
    fuck := fuck + chr(ord(S[I]) *  key);
  end;
  Result := fuck;
end;

function DecryptStr(const S: String; Key: Integer): String;
var I: Integer;
    fuck : string;
begin
  for I := 1 to Length(S) do begin
    fuck := fuck + chr(ord(S[I]) div key) // DIV the char
  end;
  Result := fuck;
end;

var str := EncryptStr('warleyalex', 2);  
WriteLn(str);
WriteLn( DecryptStr('îÂäØÊòÂØÊð', 2) ); //warleyalex



#3 COMFIED

COMFIED
  • Members
  • 44 posts

Posted 30 June 2016 - 06:00 PM

Thanks. It works







Also tagged with one or more of these keywords: Delphi, Encrypt, Security

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users