XORing long strings opimization?
Noen
not.available at na.no
Tue Nov 4 14:01:19 EST 2003
def XOR(s1,s2):
""" XOR string s1 with s2 """
output = ""
# Argument check
if (type(s1) and type(s2)) != type(""):
raise TypeError, "Arguments are not strings"
if len(s1) != len(s2):
raise ValueError, "Size differs in strings"
# Xoring
for c1 in s1:
for c2 in s2:
output += chr(ord(c1) ^ ord(c2))
return output
This way is very slow for large strings.
Anyone know of a better and faster way to do it?
More information about the Python-list
mailing list