Jump to content
COMFIED

Encryption source code from Delphi to SMS

Recommended Posts

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 := char(byte(S) xor (Key shr 8));
    Key := (byte(Result) + 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 := char(byte(S) xor (Key shr 8));
   Key := (byte(S) + Key) * C1 + C2;
  end;
end;
 

 

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×