On Thu, Jul 30, 2009 at 8:49 AM, prasad rao <prasadarao...@gmail.com> wrote:

>
>
> On 7/30/09, Rich Lovely <roadier...@googlemail.com> wrote:
>>
>> 2009/7/30 prasad rao prasadarao...@gmail.com:
>
>
>
>
> >I'm sure there are modules available for PGP that are either part of
>> >the stdlib, or available from a quick google.  PGP (or GPG) encryopts
>>
>
>       I never know there is an encryption module in stdlib.
> What is its name?
>

If you're only partially concerned (i.e. don't care about 'real' encryption)
you can use some of the string library encryptions.

def test_encod(mystr):
     mystr = str(mystr)
     print "%s zip encoded: %s" % (mystr, mystr.encode('zip'))
     print "%s rot13 encoded: %s" % (mystr, mystr.encode('rot13'))
     print "%s hex encoded: %s" % (mystr, mystr.encode('hex'))
     print "%s Base 64 encoded: %s" % (mystr, mystr.encode('base64'))


In [41]: test_encode("The quick brown fox jumps over the lazy dogs")
The quick brown fox jumps over the lazy dogs zip encoded: xœ

ÉHU(,ÍLÎVH*Ê/ÏSH˯PÈ*Í-(VÈ/K-R(Jç$VU*¤ä§l)M
The quick brown fox jumps over the lazy dogs rot13 encoded: Gur dhvpx oebja
sbk whzcf bire gur ynml qbtf
The quick brown fox jumps over the lazy dogs hex encoded:
54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f6773
The quick brown fox jumps over the lazy dogs Base 64 encoded:
VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZ3M=

So you could easily convert with encode and then reconvert with decode.

Another option would be a simple XOR of your data ( from here:
http://www.evanfosmark.com/2008/06/xor-encryption-with-python/ )

from itertools import izip, cycle

def xor_crypt_string(data, key):
    return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))

On the page provided someone also gave their code that can encrypt files.

Of course any of these methods presume you're just trying to keep the casual
snoop from getting access to your data. Anyone with time/inclination/tools
can go ahead and break most encryptions.

HTH,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to