(100%) translate these lines of code into PHP

Source: Internet
Author: User
(100%) translate these lines of code into PHP
Const XorKey: array [0 .. 7] of Byte = ($ B2, $09, $ AA, $55, $93, $ 6D, $84, $47 ); // function Dec (Str: String): String for String encryption; // What is the character decryption letter? Vari, j: Integer; beginResult: = ''; j: = 0; for I: = 1 to Length (Str) p 2 do begin Result: = Result + Char (StrToInt ('$' + Copy (Str, I * 2-1, 2) xor XorKey [j]); j: = (j + 1) mod 8; end;



Just the above lines of code,
Ask php to help translate this function into php,
I encrypted delphi and decrypted it in php,


I don't know anything about php, but I know how to call it.


Reply to discussion (solution)

Solved 200 points

There is also a post is 100 points: http://bbs.csdn.net/topics/390998635

Give a ciphertext. let me test it ~

  

Function Dec ($ str) {$ XorKey = array (0xB2, 0x09, 0xAA, 0x55,0x93, 0x6D, 0x84,0x47 ); $ result = ""; for ($ I = 0, $ j = 0; $ I
   
   

Can you translate the encryption function as well?

Function Enc (Str: String): String; // character encryption letter? ? Yes ?? Or encryption
Var
I, j: Integer;
Begin
Result: = '';
J: = 0;
For I: = 1 to Length (Str) do
Begin
Result: = Result + IntToHex (Byte (Str [I]) xor XorKey [j], 2 );
J: = (j + 1) mod 8;
End;
End;



Good test ciphertext

Give a ciphertext. let me test it ~




The ciphertext F76DC321A1 should be Edit2, but the php file you translated is that the edited file has one missing


Give a ciphertext. let me test it ~




The ciphertext F76DC321A1 should be Edit2, but the php file you translated is that the edited file has one missing


      
This is definitely okay.

$ XorKey = array (0xB2, 0x09, 0xAA, 0x55,0x93, 0x6D, 0x84,0x47); echo $ s = enc ('edit2 ', $ XorKey), PHP_EOL; echo dec ($ s, $ XorKey); function Enc ($ Str, $ XorKey) {//: String; // character encryption letter? ? Yes ?? Or encrypt $ Result = ''; $ j = 0; for ($ I = 0; $ I
     
      
F76DC321A1
      
Edit2

Can you translate the encryption function as well?

Function Enc (Str: String): String; // character encryption letter? ? Yes ?? Or encryption
Var
I, j: Integer;
Begin
Result: = '';
J: = 0;
For I: = 1 to Length (Str) do
Begin
Result: = Result + IntToHex (Byte (Str [I]) xor XorKey [j], 2 );
J: = (j + 1) mod 8;
End;
End;



Good test ciphertext



        

To: xuzuning moderator. I keep making mistakes in your code and don't know why.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.