A
A
AlexPancho2018-06-08 08:19:05
Python
AlexPancho, 2018-06-08 08:19:05

Is there a CryptJS Wordarray equivalent in Python?

In general, all crypto calculations and hashes through CryptJS and Python are the same (tested on people :).
Except in one case, hashing a string:

parse: function (hexStr) {
            // Shortcut
            var hexStrLength = hexStr.length;
            // Convert
            var words = [];
            for (var i = 0; i < hexStrLength; i += 2) {
                words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
            }
            return new WordArray.init(words, hexStrLength / 2);
        }

this procedure - WordArray - turns the hash passed to it like this:
869d4578474812f1fd5026755c691ddbf48c6bfd84292235ddbe6e78c748ec4c307d51dd341899cf7e15.......

into an array like this:
{'sigBytes': 256, 'words': [-1846127087, -525984258, 1421638880, 693604242, -431093699, -1835349658, -802431828, 512627615, 1875065943, -247975330, 958956649, -1884646837, -801131195 ...........

And then the usual hash function is taken, which is the same in JS and Py3.
But the hash results won't match - Python takes a hash from a hex number, while JS vs CryptJS takes an array of numbers.
So far this has been resolved through the js2py library that traces the code.
But, perhaps you have met, or know how to implement WordArray in python?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question