Brothers and sisters with the environment to help operate

Source: Internet
Author: User
Tags base64 encode
Brothers and sisters with the environment to help run under.
Test data $str1= "1149395524", $str 2 = "4255390370"

Xor
function My_xor ($text, $key)
{
$i = 0;
$encrypted = "";
foreach (Str_split ($text) as $char) {
$encrypted. = Chr (ord ($char) ^ ord ($key {$i + +% strlen ($key)}));
}
return $encrypted;
}

Base64 encode
function My_generate_sign ($str 1, $str 2)
{
$xorstr = My_xor ($str 1, $str 2);
Return Base64_encode ($XORSTR);
}

I wrote Java based on this XOR and Base64 encryption, but the data did not seem the same, trouble with the environment of friends to help me run, by the way to explain the My_xor ($text, $key) method, see if I understand the error.
------to solve the idea----------------------
bqmbdaaabqyfba==

What does Java have?
------to solve the idea----------------------
$text = ' 1149395524 ';
$key = ' 4255390370 ';
$s = My_xor ($text, $key);
echo Base64_encode ($s), php_eol;//requires Base64 encoding because it contains invisible characters. You decode it, you restore it.
Print_r (Unpack (' c* ', $s)); Decimal Inside Code

Xor
function My_xor ($text, $key)
{
$i = 0;
$encrypted = "";
foreach (Str_split ($text) as $char) {
$encrypted. = Chr (ord ($char) ^ ord ($key {$i + +% strlen ($key)}));
}
return $encrypted;
}
bqmbdaaabqyfba==
Array
(
[1] = 5
[2] = 3
[3] = 1
[4] = 12
[5] = 0
[6] = 0
[7] = 5
[8] = 6
[9] = 5
[Ten] + 4
)

  • Related Article

    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.