I am implementing DES3 in Python using Crypto library. I was doing some test when I’ve stumbled upon the next problem:
If the plain text that I want to encrypt contains strange charactes, as accents, fails.
For example, my code is working fine when I try to encrypt the next word:
Text to be encrypted(multiple of 8 in length) : "Hello Jose "
However, it fails if I try to encrypt the same text but containing an accent:
Text to be encrypted (multiple of 8 in length)= "Hello José "
The error that I am getting is “ValueError: Input strings must be a multiple of 8 in length”.
If I check the length of the word, it is a multiple of 8.
plaintext="Hello Jose "
print(" Plain text:" + plaintext)
print(" Plain Text length:" + str(len(plaintext)))
Result: Plain Text length : 16
Find next a reduced example of my code:
from Crypto.Cipher import DES3
import binascii
import base64
plaintext="Hello Jose "
print(" Plain text:" + plaintext)
print(" Plain Text length:" + str(len(plaintext)))
#### ENCRYPTION
key ='173JKL3D93A9CNI1G6NP9A14'
key=bytes(key, 'utf-8')
plaintext_bytes=bytes(plaintext, 'utf-8')
print(" Plain Text length:" + str(len(plaintext_bytes)))
cipher_encrypt=DES3.new(key)
encrypted_text=cipher_encrypt.encrypt(plaintext_bytes)
print( " Encrypted word:" + str(encrypted_text))
#### DECRYPTION
cipher_encrypt=DES3.new(key)
decrypted_text=cipher_encrypt.decrypt(encrypted_text)
print(" Decripted text:" + str(decrypted_text,'utf-8') + "\n")
Can anyone help me to understand why it is not working correctly?