miohtama / desfire

MIFARE DESFire NFC communication protocol for Python

Home Page:https://desfire.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not working in python 2

dejansa opened this issue · comments

commented

I found issue in authenticate method.

problem is bytes which is different in python 2 and python 3
in python 2 it is alias to str:
bytes = str

in python 3 it is: “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256

I think this will explain it better:

In [1]: private_key=[0x00] * 16

In [2]: private_key
Out[2]: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

In [3]: bytes(private_key)
Out[3]: '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]'

In [4]: def bytes(k):
   ...:     return str(bytearray(k))
   ...: 

In [5]: bytes(private_key)
Out[5]: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

problem first appears in line:
k = pyDes.triple_des(bytes(private_key), pyDes.CBC, initial_value, pad=None, padmode=pyDes.PAD_NORMAL)

beacuse pyDes.triple_des expects sequence of bytes as first parameter it fails

I solved it by hiding original python 2 bytes with one from my example, but I am not sur wil that work in python 3 and is it right way to solve this issue.

then I found another issue but let solve this first.

This issue hasn't solved yet? @dejansa how did you solve this issue?