xxtea/xxtea-python

xxtea-python results not matching xxxtea-pecl, xxtea-c, or xxtea-js

jondale opened this issue · 3 comments

I am unable to get the python lib to match results from other languages xxtea libs.

I am using the following parameters:
key = 1234567890123456
str = TEST MESSAGE

I am encrypting and then base64 encode the answer.

The python lib gives me the result:
zH1tvARq5Vo+DR3PlcvPgA==

All other libs I have tried give me the result:
UooYNJx42NPS4lWOVBFaNw==

Below is the code I'm using for each one:

xxtea-python

import xxtea
import base64

key = "1234567890123456"
msg = "TEST MESSAGE"

encrypted_data = xxtea.encrypt(msg, key)
encoded = base64.b64encode(encrypted_data)

print encoded

xxtea-pecl

$key = "1234567890123456";
$str = "TEST MESSAGE";

$encrypted_data = xxtea_encrypt($str, $key);
$encoded = base64_encode($encrypted_data);

print $encoded;

xxtea-c on an arduino

//https://github.com/xxtea/xxtea-c
#include "xxtea.h"

//https://github.com/boseji/rBASE64
#include "rBase64.h"


void setup() {
  
  Serial.begin(115200);
  Serial.println();

  const char *key = "1234567890123456";
  const char *text = "TEST MESSAGE";
  size_t len;
  
  unsigned char *s = xxtea_encrypt(text, strlen(text), key, &len);
  
  String encoded = rbase64.encode(s, len);

  Serial.println(encoded);
}

void loop() {
    
}

xxtea-js

<!DOCTYPE html>
<html>
    <head>
        <title>XXTEA test</title>
        <meta charset="UTF-8">
        <script src="xxtea.min.js" type="text/javascript"></script>
    </head>
    <body>
        <script type="text/javascript">
            var str = "TEST MESSAGE"; 
            var key = "1234567890123456";
            var encrypt_data = XXTEA.encryptToBase64(str, key);
            console.log(encrypt_data);
        </script>
    </body>
</html>
andot commented

Maybe you installed wrong module. I tested this code:

import xxtea
import base64

key = "1234567890123456"
msg = "TEST MESSAGE"

encrypted_data = xxtea.encrypt(msg, key)
encoded = base64.b64encode(encrypted_data)

print encoded

The result is:

UooYNJx42NPS4lWOVBFaNw==

Do you installed this module:

pip install xxtea-py

Thank you andot. That must have been it. I have installed the correct one now and it works.

Also as a tangent note, when I pip install xxtea-py on Fedora 25 the __pycache__ directory was not created and was giving me an error when trying to use xxtea-py. I created the directory /usr/lib/python2.7/site-packages/xxtea/__pycache__ on my machine and it works fine.

import xxtea
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Traceback (most recent call last):