1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [pycrypto] string XOR
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20string%20XOR&In-Reply-To=09787EF419216C41A903FD14EE5506DD030CF16B26%40AUSX7MCPC103.AMER.DELL.COM">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="000487.html">
<LINK REL="Next" HREF="000489.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[pycrypto] string XOR</H1>
<B>Dean Macinskas</B>
<A HREF="mailto:pycrypto%40lists.dlitz.net?Subject=%5Bpycrypto%5D%20string%20XOR&In-Reply-To=09787EF419216C41A903FD14EE5506DD030CF16B26%40AUSX7MCPC103.AMER.DELL.COM"
TITLE="[pycrypto] string XOR">dmacinskas at geobridge.net
</A><BR>
<I>Fri Oct 28 10:42:17 CST 2011</I>
<P><UL>
<LI>Previous message: <A HREF="000487.html">[pycrypto] string XOR
</A></li>
<LI>Next message: <A HREF="000489.html">[pycrypto] string XOR
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#488">[ date ]</a>
<a href="thread.html#488">[ thread ]</a>
<a href="subject.html#488">[ subject ]</a>
<a href="author.html#488">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Paul,
Thanks. It seems that in 2.7.2 the conversion is automatic: in other words, hex(int("ffffffffffffffff") == "ffffffffffffffff".
Dean
-----Original Message-----
From: <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A> [mailto:<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A>] On Behalf Of <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">Paul_Koning at Dell.com</A>
Sent: Friday, October 28, 2011 9:30 AM
To: <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
Subject: Re: [pycrypto] string XOR
Python 2 has "int" and "long" types -- long is what crypto folks call "bignum". Arithmetic operations work on both. So if you want to do arithmetic on values too big for an int, put them into a long and do it then.
In Python 3, there is only "int" which is what used to be "long" (the small integer type went away) so the whole issue goes away.
paul
-----Original Message-----
From: <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A> [mailto:<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A>] On Behalf Of Dean Macinskas
Sent: Friday, October 28, 2011 8:58 AM
To: PyCrypto discussion list
Subject: Re: [pycrypto] string XOR
Dwayne,
I've been offline for a few days, so I apologize for the delay. I'm a new pycrypto user, and missed this - I appreciate the heads-up.
I've got a followup question too: I need to do bit shifts on long (8 or 16 byte) strings. I can't see any simple way to do this; the built-in Python bit shift functions only work on integers and don't seem to have multi-precision extensions. Any advice on how to do this?
Thanks again,
Dean
-----Original Message-----
From: <A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A> [mailto:<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto-bounces at lists.dlitz.net</A>] On Behalf Of Dwayne C. Litzenberger
Sent: Saturday, October 22, 2011 4:24 PM
To: PyCrypto discussion list
Subject: Re: [pycrypto] string XOR
On Fri, Oct 21, 2011 at 03:09:36PM +0100, Richard Moore wrote:
><i>On Fri, Oct 21, 2011 at 2:55 PM, Dean Macinskas
</I>><i><<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dmacinskas at geobridge.net</A>> wrote:
</I>>><i>     ke = operator.xor(kbpkb,ve)
</I>>><i>
</I>>><i> TypeError: unsupported operand type(s) for ^: 'str' and 'str'
</I>>><i>
</I>>><i> Is there a way to do this in native Python (I'm using 2.7.2), or must
</I>>><i> I use a library of some sort?
</I>><i>
</I>><i>Use ord() to convert each character to a number first, then chr() to
</I>><i>convert the number back to a character.
</I>
Also, if you're using PyCrypto anyway, you can use its fast C implementation of a byte-wise string XOR:
from Crypto.Util.strxor import strxor
--
Dwayne C. Litzenberger <<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">dlitz at dlitz.net</A>>
OpenPGP: 19E1 1FE8 B3CF F273 ED17 4A24 928C EC13 39C2 5CF7 _______________________________________________
pycrypto mailing list
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A>
_______________________________________________
pycrypto mailing list
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A>
_______________________________________________
pycrypto mailing list
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">pycrypto at lists.dlitz.net</A>
<A HREF="http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto">http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto</A>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="000487.html">[pycrypto] string XOR
</A></li>
<LI>Next message: <A HREF="000489.html">[pycrypto] string XOR
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#488">[ date ]</a>
<a href="thread.html#488">[ thread ]</a>
<a href="subject.html#488">[ subject ]</a>
<a href="author.html#488">[ 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>
|