Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support with xtea3 #5

Closed
Varbin opened this issue Jan 10, 2015 · 5 comments
Closed

Python 3 support with xtea3 #5

Varbin opened this issue Jan 10, 2015 · 5 comments

Comments

@Varbin
Copy link
Owner

Varbin commented Jan 10, 2015

No description provided.

@theStack
Copy link

Is development of xtea3 still active?
I've looked into the module trying to make it Python 3 compatible, the following steps were needed:

  • remove the 'L' suffix from constants in methods _encrypt and _decrypt, as this is not valid in Python 3 anymore (not sure though if it hurts if missing in Python 2.x)
  • replace all '/' operators with '//' (floor division, available since Python 2.2)
  • put parantheses around ordinary print statements
  • rewrite print statements directing output to stderr (e.g. sys.stderr.write("foobar\n") which both works in Python 2 and 3)
  • define a dummy function for ord() just returning the passed value if we use Python 3, e.g.:

if sys.version_info.major >= 3: def ord(c): return c

  • use b"".join(...) instead of "".join(...) in methods encrypt and decrypt to create byte strings
  • let both functions xor_strings and _crypt_ofb return a byte string rather than a string by applying .encode("latin-1") to the return value (this unfortunately breaks compatibility with Python 2)
  • replace long by int in function stringToLong (long doesn't exist anymore in Python 3)
  • replacing types.IntType, types.LongType, types.FloatType with int, int, float, respectively

@Varbin
Copy link
Owner Author

Varbin commented Oct 15, 2016

xtea3 is even working (https://github.com/Varbin/xtea3) but not working with python 3 python 2.

But I think it's better to have one codebase for both, too.

By the way: Why does .encode("latin-1") break compatibility in Python2? In Python 2 the function will return a string ( an encoded string is still a string) and on Python 3 it should return bytes.

Latin-1 seems to be ASCII in python 2...

@Varbin
Copy link
Owner Author

Varbin commented Oct 16, 2016

Thank you for your contribution, I added many of your ideas to the code.

I made following changes to your steps:

  • Instead of using dummy ord, I defined b_ord and b_chr.
  • xor_strings behaves different on python 2 and python 3
  • import from __future__ for the print function in python 2 and 3
  • The test function will raise an exception if there is an error, so no need to write to stderr
  • The code for types.IntType, etc. is not needed anymore

@chrisrossi
Copy link

Any possibility of a release to get Python 3 support? Tests seem to work on master in Python 2 and Python 3. If there's a blocking issue, maybe I can help. Let me know.

@Varbin
Copy link
Owner Author

Varbin commented Nov 4, 2016

The current master is fully working under Python 3 (and 2). But thanks @chrisrossi . A release will be released in the next few days.

@Varbin Varbin closed this as completed Nov 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants