Giter Site home page Giter Site logo

Comments (2)

EnhboldH avatar EnhboldH commented on August 16, 2024

print ("%r" %cipher_text)

from pydes.

twhiteman avatar twhiteman commented on August 16, 2024

The r'...' produces a (unicode) string in Python3.

When using Python3 - you would need to convert to bytes to pass into pyDes - example:

$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import pyDes
>>> key = '01234567'
>>> d = pyDes.des('01234567', padmode=pyDes.PAD_PKCS5)
>>> text = r'一对一异或操作,得到结果,其中,"ord(char)"得到该字符对应的ASCII码,"chr(int)"刚好相反'

>>> d.encrypt(text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/toddw/.local/lib/python3.8/site-packages/pyDes.py", line 655, in encrypt
    data = self._guardAgainstUnicode(data)
  File "/home/toddw/.local/lib/python3.8/site-packages/pyDes.py", line 241, in _guardAgainstUnicode
    raise ValueError("pyDes can only work with encoded strings, not Unicode.")
ValueError: pyDes can only work with encoded strings, not Unicode.

>>> type(text)
<class 'str'>
>>> print ('%r' % (text, ))
'一对一异或操作得到结果,其中,"ord(char)"得到该字符对应的ASCII码,"chr(int)"刚好相反'

>>> d.encrypt(bytes(text, 'utf-8'))
b'\x05\x8b9\xad\xa8\xaa5Y\x15Q\x8b\xfd\x97O\xa8\xed\xa9\x9dz\x0c\xbe\xbc\x12\x8b\xb7\x89\x13\x9b/,\x85\xa2[^\x9e%w\n<_\xa7\xe9{\x81#\xbb\tt\x96\x94\x84ip&\xde[\xab9\xdeP/\x94\xc7\xe6\xe0\x14W)\x85-\xf8Q\x19G\x92q\xe4^wq\x93\xeb\xe1\x9c\x0c\x1a\xf9\x07\xeb\xea\x82\xd0\x9a\xad\xa7\x0e/\xb3\xa765,\xf6\xf7\x1a\xeef\xca\x88\x8a\x91P'

from pydes.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.