Mail extraction problem (something's wrong with split methods)
Luka Milkovic
luka.milkovic at public.srce.hr
Sun Sep 12 14:13:54 EDT 2004
On Sun, 12 Sep 2004 18:11:38 +0200, Diez B. Roggisch wrote:
> Well, you could certainly code around these special cases - however, it
> seems to me that whatever generates this mail is malfunctioning. Not on the
> transport-layer, but from the thing that produces this
>
> ---Code block---
>
> thingy.
The thing that produces this Code block thingy is a /dev/random output.
I'm actually building a primitive One-time pad:) Here is the code (not
translated, but you'll understand I think):
duljina_grupe = 4
dev_random = open("/dev/random")
P = select.poll()
P.register(dev_random.fileno(),select.POLLIN)
grupe = []
while len(grupe) < gener:
grupa = ""
while len(grupa) < duljina_grupe:
if P.poll(0.1):
datum = ord(dev_random.read(1))
if datum < 200:
grupa+="%2.2d"%(datum%100)
else:
print "Nedovoljna kolicina entropije u /dev/random! Pomaknite misa"
print "Za sada generirano %d grupa"%len(grupe)
grupe.append(int(grupa))
And overlapping it with text transfered in ASCII format:
grupe = []
for char in otv:
grupe.append(ord(char))
f2 = open("OTpad.pad","r")
prvi = pickle.load(f2)
enc_txt = map(lambda x,y: (x or 0) ^ (y or 0),prvi,grupe)
This enc_txt is the thingy which is mailed... Do you see any mistakes?
> What is that actually for? It looks as if you try to reinvent the wheel
> and produce your own encoding scheme for binary data - instead of doing
> this, I suggest you use one of the several available standards, like
> uuencode or others. These are covered by standard apis in python as well
> as in other languages. Better go for them.
>Straight-line brute forcing it:
>msg = .... # get the message as a tuple
>sep = "---Code block---"
>start = msg[1].index(sep)
>data = msg[1][start+1:]
>end = data.index(sep)
>data = data[:end]
>print "".join(data)[1:-1].split(", ")
Thanks Pierre, I'll try something like that later.
Luka
More information about the Python-list
mailing list