In Python 3, strings are not encoded and therefore cannot be encrypted (unless one silently performs some arbitrary encoding like Latin 1). In Python 2, strings and encoded strings (that is, a "bytes" object) were mixed and your example would have worked.
The line:
message = 'To be encrypted'
should be:
message = b'To be encrypted'
In Python 3, strings are not encoded and therefore cannot be encrypted (unless one silently performs some arbitrary encoding like Latin 1). In Python 2, strings and encoded strings (that is, a "bytes" object) were mixed and your example would have worked.
See here:
http:// eli.thegreenpla ce.net/ 2012/01/ 30/the- bytesstr- dichotomy- in-python- 3/