Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:08:40+00:00 2026-06-05T07:08:40+00:00

I would like to convert this PHP code $a ^ $b (where length of

  • 0

I would like to convert this PHP code$a ^ $b(where length of a is 16, b is 32) to javascript code. Here is my implementation.

    var xor = "";
    for (var i = 0; i < a.length; i++) {
        xor += String.fromCharCode(a.charCodeAt(i) ^ b.charCodeAt(i));
    }
    xor = b.substr(-16) + xor;

However, the result not the same. Please help me to figure it out. Thanks.

By the way, here’s the part of code I’m working around:

    var secret = "secret";
    var password = "password";
    var chal = "2ba5565a539c57c1ce2356e218faa321";
    var hexchal = php.pack('H32', chal);
    var newchal, newpwd, pappassword;

    newchal = php.pack('H*', php.md5(hexchal + secret));
    newpwd = php.pack("a32", password);
    var xor = "";
    for (var i = 0; i < newchal.length; i++) {
        xor += String.fromCharCode(newchal.charCodeAt(i) ^ newpwd.charCodeAt(i));
    }
    xor = newpwd.substr(-16) + xor;

The corresponding PHP code:

    <?php
    $secret = "secret";
    $password = "password";
    $chal = "2ba5565a539c57c1ce2356e218faa321";

    $hexchal = pack ("H32", $chal);
    $newchal = pack ("H*", md5($hexchal . $secret));

    $newpwd = pack("a32", $password);
    $pappassword = implode ("", unpack("H32", ($newpwd ^ $newchal)));
    echo $pappassword;
    ?>

Where a and b are newchal and newpwd, respectively. And php.func()s come from http://phpjs.org/. The expected output is “821f984aa1062e56dbdc8f77454e5eb3”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:08:41+00:00Added an answer on June 5, 2026 at 7:08 am

    I’ve used your code almost literally:

    String.prototype.xor = function(other)
    {
      var xor = "";
      for (var i = 0; i < this.length && i < other.length; ++i) {
          xor += String.fromCharCode(this.charCodeAt(i) ^ other.charCodeAt(i));
      }
      return xor;
    }
    

    The loop should stop when the end of either string is reached.

    Tested with:

    String.prototype.toHex = function() {
        var hex = '', tmp;
        for(var i=0; i<this.length; i++) {
            tmp = this.charCodeAt(i).toString(16)
            if (tmp.length == 1) {
                tmp = '0' + tmp;
            }
            hex += tmp
        }
        return hex;
    }
    
    var x = "password\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000";
    var y = "\u00f2~\u00eb9\u00d6i\\2\u00db\u00dc\u008fwEN^\u00b3";
    
    x.xor(y).toHex();
    

    Output:

    821f984aa162e56dbdc8f77454e5eb3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the PHP regular expression I would like to convert into a JavaScript
I would like to convert this string foo_utf = u'nästy chäräctörs with å and
i would like to reproduce/convert this js script to a php script, is there
I would like to convert this fluent approach to xml: container.Register( AllTypes.FromAssemblyNamed(Company.DataAccess) .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(), AllTypes.FromAssemblyNamed(Framework.DataAccess.NHibernateProvider)
I am learning jquery and would like to learn how to convert this server
I would like to convert a yyyy-mm-dd to something like this: Saturday, 2 October
This is a similar question to this one . I would like to convert
I would like to ask for assistance on how to convert the code below
I would like to convert an absolute path into a relative path. This is
Hello everybody, I have a small code in PHP that I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.