1

I receive a get request from server, but is encrypted with a simple algorithm in Python, so I have this Method in ActionScript for decrypt this :

public static function Decrypt (encrypted : String) : String
{
var resultArray : ByteArray = new ByteArray();
for (var i:int = 0; i < encrypted.length; i++){
resultArray.writeByte(encrypted.charCodeAt(i) ^ 0x34);
} var resultString : String = resultArray.toString();
return resultString;
}

Now, I need to implement this function in Javascript, but there is no ByteArray class in JS, any idea of how i can do this? Code and librarys are welcome.

3 Answers 3

1
 function Decrypt(encrypted) {
    var resultString = '';
    for (var i = 0; i < encrypted.length; i++) {
        resultString += String.fromCharCode(encrypted.charCodeAt(i) ^ 0x34);
    } 
    return resultString;
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the fromCharCode function is what i was looking for :D
1

Try something like this:

function Decrypt(encrypted) {
    var resultString = '';
    for (var i = 0; i < encrypted.length; i++) {
        resultString += (encrypted[i] ^ 0x34);
    } 
    return resultString
}

3 Comments

why the post was downvoted? If you don't tell I can't improve the answer.
the typo was corrected. Don't work how? Is there is any error message? Can't test without some sample data...
Missed String.fromCharCode function, that's the detail, check @Diode answer
0

Just replace it with a normal JS array ( [] ) and change resultArray.writeByte to resultArray.push. Also make resultArray.toString() into resultArray.join(''). All the rest of the code should work as is (assuming you drop things like public static, : String, :int, etc that aren't valid in JS)

1 Comment

What about the writeByte function? Should I use push instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.