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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...