Skip to content

Instantly share code, notes, and snippets.

@add1ct3d
Forked from komuw/pycrypto_DES3.py
Created August 5, 2019 17:15
Show Gist options
  • Save add1ct3d/7b87653de908c479b59b4adeaa55f77c to your computer and use it in GitHub Desktop.
Save add1ct3d/7b87653de908c479b59b4adeaa55f77c to your computer and use it in GitHub Desktop.

Revisions

  1. @komuw komuw revised this gist Feb 12, 2016. No changes.
  2. @komuw komuw revised this gist Feb 12, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions pycrypto_DES3.py
    Original file line number Diff line number Diff line change
    @@ -20,3 +20,7 @@
    key size (must be either 16 or 24 bytes long)
    """
    """
    https://pythonhosted.org/pycrypto/Crypto.Cipher.DES3-module.html
    https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
    """
  3. @komuw komuw revised this gist Feb 11, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions pycrypto_DES3.py
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,6 @@
    For MODE_CFB, plaintext length (in bytes) must be a multiple of segment_size/8.
    For MODE_CTR, plaintext can be of any length.
    For MODE_OPENPGP, plaintext must be a multiple of block_size, unless it is the last chunk of the message.
    key size (must be either 16 or 24 bytes long)
    """
  4. @komuw komuw revised this gist Feb 11, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions pycrypto_DES3.py
    Original file line number Diff line number Diff line change
    @@ -11,3 +11,10 @@
    cipher_decrypt = DES3.new(key, DES3.MODE_OFB, iv) #you can't reuse an object for encrypting or decrypting other data with the same key.
    cipher_decrypt.decrypt(encrypted_text)
    cipher_decrypt.decrypt(encrypted_text) #you cant do it twice

    """
    For MODE_ECB, MODE_CBC, and MODE_OFB, plaintext length (in bytes) must be a multiple of block_size.
    For MODE_CFB, plaintext length (in bytes) must be a multiple of segment_size/8.
    For MODE_CTR, plaintext can be of any length.
    For MODE_OPENPGP, plaintext must be a multiple of block_size, unless it is the last chunk of the message.
    """
  5. @komuw komuw created this gist Feb 11, 2016.
    13 changes: 13 additions & 0 deletions pycrypto_DES3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    `pip install pycrypto`

    from Crypto.Cipher import DES3
    from Crypto import Random
    key = 'Sixteen byte key'
    iv = Random.new().read(DES3.block_size) #DES3.block_size==8
    cipher_encrypt = DES3.new(key, DES3.MODE_OFB, iv)
    plaintext = 'sona si latine loqueri ' #padded with spaces so than len(plaintext) is multiple of 8
    encrypted_text = cipher_encrypt.encrypt(plaintext)

    cipher_decrypt = DES3.new(key, DES3.MODE_OFB, iv) #you can't reuse an object for encrypting or decrypting other data with the same key.
    cipher_decrypt.decrypt(encrypted_text)
    cipher_decrypt.decrypt(encrypted_text) #you cant do it twice