Hack Forums
[Help] Is there an equivalent of Encode in PERL written in Python? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Is there an equivalent of Encode in PERL written in Python? (/showthread.php?tid=6238504)



Is there an equivalent of Encode in PERL written in Python? - Airbourne - Apr 8, 2023

I recently re-discovered rc1342 and how well spoofing can be done with it, sometimes even bypassing e-mail security sandboxes.
Only problem is, im very much a novice with Python having written only a few simple scripts working with various APIs so simple stuff with documentation.
Encode in PERL can automatically encode each MIME header with the required set and I couldn't find a simple tool that does all that for the life of me and my attempts at coding this in Python have failed.
To add detail to this I basically need a tool that can encode text into various charsets such as ISO-8859-X


RE: Is there an equivalent of Encode in PERL written in Python? - luctvmgrzfsxn754 - Apr 8, 2023

In Python, you can use the encode() method of a string object to work with ISO-8859-X encoded text. For example, to use an ISO-8859-1 encoded document, you need the following code:
Code
text = "Hello, world!"
encoded_text = text.encode("ISO-8859-1")

You can use the decode() method to decode a string from an ISO-8859-X encoding to Unicode. For example:
Code
encoded_text = b"Hello, world!"
text = encoded_text.decode("ISO-8859-1")