Delphi Encrypt Function Conversion for Javascript

Asked

Viewed 123 times

1

I’m having a problem converting this function, I wish someone would help me

Code in Delphi

function EnCripta(const InString:string; StartKey,MultKey,AddKey:Integer): string;
var I : Byte;
  begin
  Result := '';
  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;

Code in Javascrypt

var EnCripta = function (inString, startKey, multKey, addKey) {
            var I;
            var result = "";
            var vStartKey = startKey;
            for (I = 0; I < inString.length; I++) {
                var codigo = inString.charCodeAt(I) ^ (startKey >> 8);
                codigo = codigo & 0xff;
                var a = String.fromCharCode(codigo);
                result = result.toString( 'ASCII' ) + a;
                startKey = ((result.charCodeAt(I) + startKey) * multKey + addKey);
            }
            return result;
        }

Some words until it works, others don’t

Please if you have anyone help me

  • Your problem is encoding. Now just know in which of the languages. Passing the string blablabla, the Delphi returns bnm]Ĭإἴ鳜༔ and javascript returns bnm],%4Ü

  • In my case this being in javascript, because I am trying to access a password saved by Delphi

  • how can I resolve?

  • Checking a little more I arrived in the database, I’m using the Firebird, with the Node-Firebird

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.