diff options
Diffstat (limited to 'pipermail/pycrypto/2014q1/000761.html')
-rw-r--r-- | pipermail/pycrypto/2014q1/000761.html | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/pipermail/pycrypto/2014q1/000761.html b/pipermail/pycrypto/2014q1/000761.html new file mode 100644 index 0000000..bdf5515 --- /dev/null +++ b/pipermail/pycrypto/2014q1/000761.html @@ -0,0 +1,175 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> + <HEAD> + <TITLE> [pycrypto] Unicode? + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20Unicode%3F&In-Reply-To=%3CCANqwJFjV2SSsh8Ctvpi3_fDM8ssc%3DitGx%3DiJxP_z%2BuS9%3D7oX4w%40mail.gmail.com%3E"> + <META NAME="robots" CONTENT="index,nofollow"> + <style type="text/css"> + pre { + white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */ + } + </style> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="000760.html"> + <LINK REL="Next" HREF="000762.html"> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[pycrypto] Unicode?</H1> + <B>Jeremy Gray</B> + <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20Unicode%3F&In-Reply-To=%3CCANqwJFjV2SSsh8Ctvpi3_fDM8ssc%3DitGx%3DiJxP_z%2BuS9%3D7oX4w%40mail.gmail.com%3E" + TITLE="[pycrypto] Unicode?">jrgray at gmail.com + </A><BR> + <I>Mon Feb 3 04:40:14 PST 2014</I> + <P><UL> + <LI>Previous message: <A HREF="000760.html">[pycrypto] Unicode? +</A></li> + <LI>Next message: <A HREF="000762.html">[pycrypto] Unicode? +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#761">[ date ]</a> + <a href="thread.html#761">[ thread ]</a> + <a href="subject.html#761">[ subject ]</a> + <a href="author.html#761">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>I may not understand the constraints of your situation, but wouldn't +python's "universal newlines" file-open mode achieve what you want? infile += open(filename, 'Urb') + +--Jeremy + + +On Mon, Feb 3, 2014 at 5:35 AM, Dave Pawson <<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dave.pawson at gmail.com</A>> wrote: + +><i> Now resolved. +</I>><i> Source plain text is created / modified in either DOS or Linux (np to add +</I>><i> Mac) +</I>><i> +</I>><i> read using +</I>><i> chunk = unicode(infile.read(chunksize)) +</I>><i> # replace newline as appropriate +</I>><i> chunk=replaceNL(chunk) +</I>><i> # Convert to byte string +</I>><i> chunk=safe_str(chunk) +</I>><i> encrypt and write to disk +</I>><i> +</I>><i> +</I>><i> # for decrypt +</I>><i> #Iterate over file to read into string +</I>><i> # replace the individual bytes of the Unicode character (u2022 in my case) +</I>><i> # with \n for the local machine +</I>><i> retval = replaceBullet(retval) +</I>><i> +</I>><i> code below +</I>><i> +</I>><i> # +</I>><i> #Swap \n for \u2022 +</I>><i> # +</I>><i> def replaceNL(str): +</I>><i> # If DOS, replace \r\x0A +</I>><i> # If Unix, replace \n +</I>><i> lineEnd=u'\n' +</I>><i> if string.find(str,'\r\x0a'): +</I>><i> lineEnd=u'\r\x0A' +</I>><i> return string.replace(str,lineEnd,u'\u2022') +</I>><i> +</I>><i> # +</I>><i> # Replace bullet by \n +</I>><i> # +</I>><i> def replaceBullet(bstr): +</I>><i> return string.replace(bstr,u'\\u2022',u'\n') +</I>><i> +</I>><i> +</I>><i> +</I>><i> def safe_str(obj): +</I>><i> """ return the byte string representation of obj """ +</I>><i> try: +</I>><i> return str(obj) +</I>><i> except UnicodeEncodeError: +</I>><i> # obj is unicode +</I>><i> return unicode(obj).encode('unicode_escape') +</I>><i> +</I>><i> HTH others, though it seems messy, it works. +</I>><i> +</I>><i> Dave +</I>><i> +</I>><i> +</I>><i> On 3 February 2014 09:39, Dave Pawson <<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dave.pawson at gmail.com</A>> wrote: +</I>><i> > I'm having a problem 'sharing' an encrypted file between +</I>><i> > MSDOS and Linux. +</I>><i> > +</I>><i> > so I thought I'd replace \nl in the plain text with a non ASCII +</I>><i> > character prior to encryption. +</I>><i> > +</I>><i> > encryptor = AES.new(key, AES.MODE_CBC, iv) +</I>><i> > outfile.write(encryptor.encrypt(chunk)) +</I>><i> > +</I>><i> > gives me +</I>><i> > +</I>><i> > File "/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py", +</I>><i> > line 244, in encrypt +</I>><i> > return self._cipher.encrypt(plaintext) +</I>><i> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in +</I>><i> > position 34: ordinal not in range(128) +</I>><i> > +</I>><i> > +</I>><i> > It would seem I can't use non-ASCII characters, at least with AES, is +</I>><i> > this right ? +</I>><i> > +</I>><i> > If not, how to address it please? +</I>><i> > +</I>><i> > +</I>><i> > regards +</I>><i> > +</I>><i> > +</I>><i> > -- +</I>><i> > Dave Pawson +</I>><i> > XSLT XSL-FO FAQ. +</I>><i> > Docbook FAQ. +</I>><i> > <A HREF="http://www.dpawson.co.uk">http://www.dpawson.co.uk</A> +</I>><i> +</I>><i> +</I>><i> +</I>><i> -- +</I>><i> Dave Pawson +</I>><i> XSLT XSL-FO FAQ. +</I>><i> Docbook FAQ. +</I>><i> <A HREF="http://www.dpawson.co.uk">http://www.dpawson.co.uk</A> +</I>><i> _______________________________________________ +</I>><i> pycrypto mailing list +</I>><i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A> +</I>><i> <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A> +</I>><i> +</I>-------------- next part -------------- +An HTML attachment was scrubbed... +URL: <<A HREF="http://lists.dlitz.net/pipermail/pycrypto/attachments/20140203/88c7c334/attachment.html">http://lists.dlitz.net/pipermail/pycrypto/attachments/20140203/88c7c334/attachment.html</A>> +</PRE> + + + + + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="000760.html">[pycrypto] Unicode? +</A></li> + <LI>Next message: <A HREF="000762.html">[pycrypto] Unicode? +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#761">[ date ]</a> + <a href="thread.html#761">[ thread ]</a> + <a href="subject.html#761">[ subject ]</a> + <a href="author.html#761">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">More information about the pycrypto +mailing list</a><br> +</body></html> |