473,395 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Encoding / decoding strings

Hey Everyone,

Was just wondering if anyone here could help me. I want to encode (and
subsequently decode) email addresses to use in URLs. I believe that
this can be done using MD5.

I can find documentation for encoding the strings, but not decoding
them. What should I do to encode =and= decode strings with MD5?

Many Thanks in Advance,
Oliver Beattie

Jan 5 '07 #1
8 1846

ol****@obeattie.com wrote:
Hey Everyone,

Was just wondering if anyone here could help me. I want to encode (and
subsequently decode) email addresses to use in URLs. I believe that
this can be done using MD5.

I can find documentation for encoding the strings, but not decoding
them. What should I do to encode =and= decode strings with MD5?

Many Thanks in Advance,
Oliver Beattie
Depends what you mean by "encode email addresses to use in URLs". MD5
is a cryptographic one-way hash function; it creates a 'finger print'
of the input data: given this, it's impossible to reproduce the
original input.

Is this what you're looking for?
>>import urllib
urllib.quote('s**********@somedomain.com')
'some.persons%40somedomain.com'

hth
Jon.

Jan 5 '07 #2
ol****@obeattie.com wrote:
Hey Everyone,

Was just wondering if anyone here could help me. I want to encode (and
subsequently decode) email addresses to use in URLs. I believe that
this can be done using MD5.
Are you by chance after a way to create URLs that contain an email which the
server then can extract from them, and this to be tamperproof?

There are several ways to accomplish this - your MD5-suggestion is applyable
when working with a simple secret and by creating an additional parameter.

If you e.g. want an url like this to be secure

http://some.server/path?user_to_register=email@address

you use a secret, and hash the parameters together with the secret using
MD5. The result is then something like

http://some.server/path?user_to_register=email@address&key=<md5sum>

Then in the server, you perform the same step as above, without the key of
course, and simply check if the MD5-sums are equal.
Anything else requires the use of a encryption algorithm like blowfish or
whatnot, either symetric or public key - I'm not an expert on that though.

Diez
Jan 5 '07 #3
Basically, I want to encode an email address so that it looks something
like 8d2e23c0a835598510c88a758c6b215a - this way the user does not know
the email address they are looking at. They are public-facing views and
they are to get info about other users, therefore anonymity is
important.

Any suggestions?

Jan 5 '07 #4
In <11**********************@42g2000cwt.googlegroups. com>,
ol****@obeattie.com wrote:
Basically, I want to encode an email address so that it looks something
like 8d2e23c0a835598510c88a758c6b215a - this way the user does not know
the email address they are looking at. They are public-facing views and
they are to get info about other users, therefore anonymity is
important.

Any suggestions?
Don't deliver encoded e-mail addresses to other users. They might decode
them and the anonymity is gone.

What exactly are you trying to do? Why should users see encrypted e-mail
addresses of others?

Ciao,
Marc 'BlackJack' Rintsch

Jan 5 '07 #5

Marc 'BlackJack' Rintsch wrote:
In <11**********************@42g2000cwt.googlegroups. com>,
ol****@obeattie.com wrote:
Basically, I want to encode an email address so that it looks something
like 8d2e23c0a835598510c88a758c6b215a - this way the user does not know
the email address they are looking at. They are public-facing views and
they are to get info about other users, therefore anonymity is
important.

Any suggestions?

Don't deliver encoded e-mail addresses to other users. They might decode
them and the anonymity is gone.

What exactly are you trying to do? Why should users see encrypted e-mail
addresses of others?

Ciao,
Marc 'BlackJack' Rintsch
Basically, what I am trying to do is display all comments by a
specified user on the website. As the only thing which has =always=
been used to identify users which never changes is their e-mail
addresses, this is the only thing which I can use. Obviously, I can't
display this e-mail address though.

Jan 5 '07 #6
In <11**********************@11g2000cwr.googlegroups. com>,
ol****@obeattie.com wrote:
Basically, what I am trying to do is display all comments by a
specified user on the website. As the only thing which has =always=
been used to identify users which never changes is their e-mail
addresses, this is the only thing which I can use. Obviously, I can't
display this e-mail address though.
Associate a unique random number or string with each e-mail address and
use this outside the server to identify users. An MD5 hash of the
mail address might be a good candidate for such a string but then it's
possible for attackers to verify if someone they know the address of, has
made specific comments. So part of the anonymity is gone then.

Ciao,
Marc 'BlackJack' Rintsch
Jan 5 '07 #7
"ol****@obeattie.com" <ol****@obeattie.comwrites:
Basically, what I am trying to do is display all comments by a
specified user on the website. As the only thing which has =always=
been used to identify users which never changes is their e-mail
addresses, this is the only thing which I can use. Obviously, I can't
display this e-mail address though.
Assign a unique number to each user in the system, and use the number.
Email addresses aren't necessarily stable since users should be able
to change their email addresses.

If you really want to use a hash, use the hmac module:

import hmac
hash = hmac.new('swordfish', 'p*****@domain.tld').hexdigest()

where instead of swordfish you'd use some random constant string that
you keep secret. The secrecy stops attackers from figuring out
whether a given address has a specific hash per Mark Rintsch's
comment. You'll still have to main a table mapping hashes back to
addresses, since the hashes are not reversable.

If you HAVE to have reversible encryption, you could use

http://nightsong.com/phr/crypto/p3.py

note that the string you get is binary and is longer than the input
string even before you encode it to printing chars. Note also that it
reveals the length of its input.

To generate a random string, use os.urandom:

import os, binascii
secret_string = binascii.hexlify(os.urandom(16))

you'd then embed the secret string in your program or database. You
then face the problem of keeping it secret, which is not trivial.

Overall you're better off just assigning ID numbers to users like most
BBS's do.
Jan 5 '07 #8
On Fri, 05 Jan 2007 09:39:17 -0800, ol****@obeattie.com wrote:
Basically, what I am trying to do is display all comments by a
specified user on the website. As the only thing which has =always=
been used to identify users which never changes is their e-mail
addresses,
What are you talking about? I've changed my email address a dozen times
on many mailing lists and websites. I'm still me.
this is the only thing which I can use. Obviously, I can't
display this e-mail address though.
There is nothing obvious about that all all. Email addresses are usually
public. But okay, your users aren't expecting their email address to be
public.

Why not do what many jails do with prisoners? Everybody gets a unique
number. In your case, just walk through the database of users, giving
each one a number. You can't reverse engineer the email address from the
number without breaking into the database. Then your website can refer to
them as "Prisoner 123456789" which should be good for a few laughs.

Or simply take the username part of the address. So "fr**@hotmail.com"
would become "fred". Then "fr**@gmail.com" would become "fred1", and so
forth.

Obviously you don't try to generate the username from the email address
every single time, you do it once, and keep a list of used usernames so
that when "fr**@yahoo.com" joins you know "fred" and "fred1" are both used
and he has to be "fred2".

md5 checksums can now be broken, in both directions: it is relatively
easy to generate collisions, and there are reverse md5 lookup tables.
I imagine your use of md5 would be especially easy to attack, since the
attacker knows that the string is an email address.

--
Steven.

Jan 6 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sebastian Meyer | last post by:
Hi newsgroup, i am trying to replace german special characters in strings like str = re.sub('ö', 'oe', str) When i work with this, i always get the message UniCode Error: ASCII decoding error...
3
by: dot | last post by:
Hi all, I have written a Python huffman Encoding Module, for my own amusement. I thought it might be educational/entertaining for other people, so I've put it on my website and wrote about it a...
30
by: aurora | last post by:
I have long find the Python default encoding of strict ASCII frustrating. For one thing I prefer to get garbage character than an exception. But the biggest issue is Unicode exception often pop up...
3
by: nly | last post by:
What's the purpose of "Base64 encoding and decoding"? Thanks in advance!
9
by: Mark | last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
37
by: Zhiv Kurilka | last post by:
Hi, I have a text file with following content: "((^)|(.* +))§§§§§§§§" if I read it with: k=System.IO.StreamReader( "file.txt",System.Text.Encoding.ASCII); k.readtotheend()
9
by: KWSW | last post by:
Having settled the huffman encoding/decoding and channel modeling(thanks to the previous part on bitwise operation), the last part would be hamming encoding/decoding. Did some research as usual on...
3
by: =?Utf-8?B?cndvb2RydWY=?= | last post by:
Hello All, I am using an HtmlTextWriter to writer out some html. Prior to sending the content to the text writer, HttpUtility.HtmlEncode the string. However, doing so results in a string where...
0
by: Michele | last post by:
Hi there, I'm using a python script in conjunction with a JPype, to run java classes. So, here's the code: from jpype import * import os import random import math import sys
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.