Delphi <> PHP XOR Encryption -


i trying encryption , decryption between php , delphi.

my php code is;

<?php error_reporting(e_all); $key = "5y';syhl0ngl4st1ngdfvt5tt";  function decrypt1($string, $key){      $y = 1;     ($x = 1;$i < strlen($string); $i++) {         $a = (ord($string[$x]) , 0x0f) ^ (ord($key[$y]) , 0x0f);         $string[$x] = chr((ord($string[$x]) , 0xf0) + $a);          $y++;         if ($y > strlen($key)) $y = 1;     }     return $string; }  echo decrypt1(base64_decode("cwx0fw=="),$key); ?> 

my delphi is;

function decrypt1(str : string; key: string): ansistring; var   x, y : integer;   : byte; begin   y := 1;   x := 1 length(str)   begin     := (ord(str[x]) , $0f) xor (ord(key[y]) , $0f);     str[x] := char((ord(str[x]) , $f0) + a);      inc(y);     if y > length(key) y := 1;   end;   result := str; end;  function encrypt(str : string; key: string): string; begin result:= decrypt1(str,key); result:= encodebase64(result); end; 

the encryption / decryption doesn't work. when attempting decode encoded value delphi in php, load of rubbish.

i have feeling might character encoding?

there few problems here:

  • string indexing in php zero-based , not one-based code assumes.
  • delphi strings (well, in modern delphi) utf-16 encoded. code assumes unspecified 8 bit encoding.
  • encryption/decryption operates on binary data rather text , fail recognise this.

you should encrypt this:

  1. encode text in specific, well-defined encoding. instance, utf-8. gives byte array. in delphi tbytes.
  2. encrypt byte array yield byte array.
  3. encode byte array using base64 text representation.

decryption reverses these steps. key thing absorb encryption/decryption operates on binary data rather text.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -