summaryrefslogtreecommitdiff
path: root/pipermail/pycrypto/2014q1/000760.html
diff options
context:
space:
mode:
Diffstat (limited to 'pipermail/pycrypto/2014q1/000760.html')
-rw-r--r--pipermail/pycrypto/2014q1/000760.html157
1 files changed, 157 insertions, 0 deletions
diff --git a/pipermail/pycrypto/2014q1/000760.html b/pipermail/pycrypto/2014q1/000760.html
new file mode 100644
index 0000000..757da50
--- /dev/null
+++ b/pipermail/pycrypto/2014q1/000760.html
@@ -0,0 +1,157 @@
+<!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=%3CCAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c%2Be2A%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="000759.html">
+ <LINK REL="Next" HREF="000761.html">
+ </HEAD>
+ <BODY BGCOLOR="#ffffff">
+ <H1>[pycrypto] Unicode?</H1>
+ <B>Dave Pawson</B>
+ <A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=Re%3A%20%5Bpycrypto%5D%20Unicode%3F&In-Reply-To=%3CCAEncD4fpFxt47dGVSLiryL8iPqZSqhJkL0YZHqSDUSML-c%2Be2A%40mail.gmail.com%3E"
+ TITLE="[pycrypto] Unicode?">dave.pawson at gmail.com
+ </A><BR>
+ <I>Mon Feb 3 02:35:03 PST 2014</I>
+ <P><UL>
+ <LI>Previous message: <A HREF="000759.html">[pycrypto] Unicode?
+</A></li>
+ <LI>Next message: <A HREF="000761.html">[pycrypto] Unicode?
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#760">[ date ]</a>
+ <a href="thread.html#760">[ thread ]</a>
+ <a href="subject.html#760">[ subject ]</a>
+ <a href="author.html#760">[ author ]</a>
+ </LI>
+ </UL>
+ <HR>
+<!--beginarticle-->
+<PRE>Now resolved.
+Source plain text is created / modified in either DOS or Linux (np to add Mac)
+
+read using
+chunk = unicode(infile.read(chunksize))
+# replace newline as appropriate
+chunk=replaceNL(chunk)
+# Convert to byte string
+chunk=safe_str(chunk)
+encrypt and write to disk
+
+
+# for decrypt
+#Iterate over file to read into string
+# replace the individual bytes of the Unicode character (u2022 in my case)
+# with \n for the local machine
+retval = replaceBullet(retval)
+
+code below
+
+#
+#Swap \n for \u2022
+#
+def replaceNL(str):
+ # If DOS, replace \r\x0A
+ # If Unix, replace \n
+ lineEnd=u'\n'
+ if string.find(str,'\r\x0a'):
+ lineEnd=u'\r\x0A'
+ return string.replace(str,lineEnd,u'\u2022')
+
+#
+# Replace bullet by \n
+#
+def replaceBullet(bstr):
+ return string.replace(bstr,u'\\u2022',u'\n')
+
+
+
+def safe_str(obj):
+ &quot;&quot;&quot; return the byte string representation of obj &quot;&quot;&quot;
+ try:
+ return str(obj)
+ except UnicodeEncodeError:
+ # obj is unicode
+ return unicode(obj).encode('unicode_escape')
+
+HTH others, though it seems messy, it works.
+
+Dave
+
+
+On 3 February 2014 09:39, Dave Pawson &lt;<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dave.pawson at gmail.com</A>&gt; wrote:
+&gt;<i> I'm having a problem 'sharing' an encrypted file between
+</I>&gt;<i> MSDOS and Linux.
+</I>&gt;<i>
+</I>&gt;<i> so I thought I'd replace \nl in the plain text with a non ASCII
+</I>&gt;<i> character prior to encryption.
+</I>&gt;<i>
+</I>&gt;<i> encryptor = AES.new(key, AES.MODE_CBC, iv)
+</I>&gt;<i> outfile.write(encryptor.encrypt(chunk))
+</I>&gt;<i>
+</I>&gt;<i> gives me
+</I>&gt;<i>
+</I>&gt;<i> File &quot;/usr/lib64/python2.7/site-packages/Crypto/Cipher/blockalgo.py&quot;,
+</I>&gt;<i> line 244, in encrypt
+</I>&gt;<i> return self._cipher.encrypt(plaintext)
+</I>&gt;<i> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in
+</I>&gt;<i> position 34: ordinal not in range(128)
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> It would seem I can't use non-ASCII characters, at least with AES, is
+</I>&gt;<i> this right ?
+</I>&gt;<i>
+</I>&gt;<i> If not, how to address it please?
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> regards
+</I>&gt;<i>
+</I>&gt;<i>
+</I>&gt;<i> --
+</I>&gt;<i> Dave Pawson
+</I>&gt;<i> XSLT XSL-FO FAQ.
+</I>&gt;<i> Docbook FAQ.
+</I>&gt;<i> <A HREF="http://www.dpawson.co.uk">http://www.dpawson.co.uk</A>
+</I>
+
+
+--
+Dave Pawson
+XSLT XSL-FO FAQ.
+Docbook FAQ.
+<A HREF="http://www.dpawson.co.uk">http://www.dpawson.co.uk</A>
+</PRE>
+
+
+
+
+
+<!--endarticle-->
+ <HR>
+ <P><UL>
+ <!--threads-->
+ <LI>Previous message: <A HREF="000759.html">[pycrypto] Unicode?
+</A></li>
+ <LI>Next message: <A HREF="000761.html">[pycrypto] Unicode?
+</A></li>
+ <LI> <B>Messages sorted by:</B>
+ <a href="date.html#760">[ date ]</a>
+ <a href="thread.html#760">[ thread ]</a>
+ <a href="subject.html#760">[ subject ]</a>
+ <a href="author.html#760">[ 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>