GithubHelp home page GithubHelp logo

twhiteman / pydes Goto Github PK

View Code? Open in Web Editor NEW
173.0 173.0 61.0 69 KB

A pure python module which implements the DES and Triple-DES encryption algorithms.

License: MIT License

Python 80.93% HTML 16.74% CSS 2.34%

pydes's People

Contributors

choldrim avatar twhiteman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydes's Issues

About unpad data function question

In code line 221:

elif padmode == PAD_PKCS5:
	if _pythonMajorVersion < 3:
		pad_len = ord(data[-1])
	else:
		pad_len = data[-1]
	data = data[:-pad_len]

If decrypt data end bytes is 0x00->0, The code data = data[:-pad_len] gave me empty data.
Sorry for my bad English.

Pydes Error generating triple des conversion

Error: ord() expected string of length 1, but int found
I have found solution for this some changing in pyDes.py

Please change in pyDes.py file on line number 418:

if _pythonMajorVersion < 3 :

TO

if _pythonMajorVersion < 3 and isinstance(data[0], str):

Invalid data length, data must be a multiple of 8 bytes

Hi

I stated pad char but still got error:
Invalid data length, data must be a multiple of 8 bytes
As I understood - in such cases data length should be increased by X number of pad chars to match block size.
Or I'm doing something wrong?

secKey = [55, 22, 5, 23, 11, 34, 48, 58]
decoder = pyDes.des(bytearray(secKey), pyDes.ECB, pad=b'\0')

decoded_data = decoder.decrypt(tcp_data)

Cannot collect pydes

Is pydes configured in pypi properly? I'm failing to fetch the package. It seems some urls were changed in e988a5f but I don't see those reflected in pypi

Looking in indexes: https://pypi.lyft.net/pypi/, https://pypi.python.org/simple/
Collecting nfcpy==1.0.3
  Using cached nfcpy-1.0.3-py3-none-any.whl (186 kB)
Collecting libusb1
  Using cached libusb1-1.9.2-py3-none-any.whl (58 kB)
Collecting pydes
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105879fa0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865130>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x1058652b0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865430>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x1058655b0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
ERROR: Could not install packages due to an EnvironmentError: HTTPConnectionPool(host='whitemans.ca', port=80): Max retries exceeded with url: /pyDES/pyDes-2.0.1.zip (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865730>, 'Connection to whitemans.ca timed out. (connect timeout=15)'))

WARNING: You are using pip version 20.2.3; however, version 21.1 is available.
You should consider upgrading via the '/Users/conormurphy/.pyenv/versions/3.9.0/envs/triangle-tool-3.9.0/bin/python3.9 -m pip install --upgrade pip' command.

Canonical "latest" version

Hi, this is packaged on NixOS, as well as some other distros: https://repology.org/project/python:pydes/versions

It seems the NixOS version is flagged because the package is based on this repository, rather than the pypi package.

Which version should be considered the canonical "latest"? The commits since 2.0.1 seem ok to me personally, is this just a case of not having time to sort out a new pypi release?

can't import pyDes

After installing pyDes by pip install pyDes when i am tying to import pyDes its showing some error.
Screenshot (123)

CBC mode adds extra bytes

Thanks for a great implementation of DES! However, I think I may have found an issue.

Describe your problem
When encrypting using the DES implementation in CBC mode, the resulting output have extra bytes at the end.

What did you expect?
An example of correct input -> output mapping

KEY = b'descrypt'
STR = b'linuslag'
c = des(KEY, CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
c.encrypt(STR * 2)
# b'2u\xdb\x12\xe5-#\x9e\xe7\x8b\x99\x85M\xcc\x9a\r'

What happened?
The actual output:

KEY = b'descrypt'
STR = b'linuslag'
c = des(KEY, CBC, b"\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
c.encrypt(STR * 2)
# b'2u\xdb\x12\xe5-#\x9e\xe7\x8b\x99\x85M\xcc\x9a\r\x93\xf4w{m7#e'

As can be seen from these examples, the actual output is the same as the expected output except it has some extra 8 bytes at the end.

(Can be validated using online tools, such as: http://extranet.cryptomathic.com/descalc/index)

Create encrypted passwords for VNC?

The tool vncpassword.py includes d3des.py, a Python implementation of 3DES with modifications to the original 3DES algorithm. The main modification seems to be:

# This is a departure from the original code.
#bytebit = [ 0200, 0100, 040, 020, 010, 04, 02, 01 ] # original
bytebit = [ 01, 02, 04, 010, 020, 040, 0100, 0200 ] # VNC version

I have no clue what that means, and I wonder: Can I use pyDes to create 3DES encrypted passwords for VNC?

Results of my tests:

$ echo SomeData | tightvncpasswd -f | xxd
0000000: 960d e668 b0d9 dd3c
$ python3 -c "import sys; import pyDes; \
des = pyDes.des([23, 82, 107, 6, 35, 78, 88, 7]); \
sys.stdout.buffer.write(des.encrypt('SomeData'))" | xxd
0000000: cd32 65aa 048d 5688                      .2e...V.
$ python3 -c "import sys; import pyDes; \
des = pyDes.triple_des([23, 82, 107, 6, 35, 78, 88, 7, 0, 0, 0, 0, 0, 0, 0, 0]); \
sys.stdout.buffer.write(des.encrypt('SomeData'))" | xxd
0000000: 23c8 ea0c bef9 ad8d                      #.......
$ python3 -c "import sys; import pyDes; \
des = pyDes.triple_des([23, 82, 107, 6, 35, 78, 88, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); \
sys.stdout.buffer.write(des.encrypt('SomeData'))" | xxd
0000000: cd32 65aa 048d 5688                      .2e...V.

The encryption key used by VNC is [23, 82, 107, 6, 35, 78, 88, 7]. This is the same for TightVNC, TigerVNC, and RealVNC. Unfortunately, as you can see, with the above command lines, I'm not able to reproduce the output of the VNC password command.

TypeError: unsupported operand type(s) for +=: 'dict' and 'bytes'

In a very simple test under python 3.7.4 i got the following error:

accesskey16 = '375bf8eda8d14185'
dataStr = b"testdata"
keying = pyDes.triple_des(
  accesskey16.encode(),
  pyDes.ECB, 
  b"\0\0\0\0\0\0\0\0", 
  pad=None,
  padmode=pyDes.PAD_PKCS5)
encStr = keying.encrypt(data)

TypeError: unsupported operand type(s) for +=: 'dict' and 'bytes', I have checked the code and couldn't figure out the issue

Cannot collect pydes

Is pydes configured in pypi properly? I'm failing to fetch the package. It seems some urls were changed in e988a5f but I don't see those reflected in pypi

Looking in indexes: https://pypi.lyft.net/pypi/, https://pypi.python.org/simple/
Collecting nfcpy==1.0.3
  Using cached nfcpy-1.0.3-py3-none-any.whl (186 kB)
Collecting libusb1
  Using cached libusb1-1.9.2-py3-none-any.whl (58 kB)
Collecting pydes
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105879fa0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865130>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x1058652b0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865430>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x1058655b0>, 'Connection to whitemans.ca timed out. (connect timeout=15)')': /pyDES/pyDes-2.0.1.zip
ERROR: Could not install packages due to an EnvironmentError: HTTPConnectionPool(host='whitemans.ca', port=80): Max retries exceeded with url: /pyDES/pyDes-2.0.1.zip (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPConnection object at 0x105865730>, 'Connection to whitemans.ca timed out. (connect timeout=15)'))

WARNING: You are using pip version 20.2.3; however, version 21.1 is available.
You should consider upgrading via the '/Users/conormurphy/.pyenv/versions/3.9.0/envs/triangle-tool-3.9.0/bin/python3.9 -m pip install --upgrade pip' command.

Upgrading to pip 21.1 works fine, but I have a bazel repo pinned to an earlier version and it cannot collect this package.

ValueError: pyDes can only work with encoded strings, not Unicode.

text = r'一对一异或操作,得到结果,其中,"ord(char)"得到该字符对应的ASCII码,"chr(int)"刚好相反'
cipher_text = Des2.des_encrypt(text)
print(cipher_text)
text = Des2.des_descrypt(cipher_text)
print(text)

Traceback (most recent call last):
cipher_text = Des2.des_encrypt(text)
File "/Des2.py", line 19, in des_encrypt
en = k.encrypt(s, padmode=PAD_PKCS5)
File "/usr/local/lib/python3.7/site-packages/pyDes.py", line 655, in encrypt
data = self._guardAgainstUnicode(data)
File "/usr/local/lib/python3.7/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.

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.