help to convert c++ fonction in python

geremy condra debatem1 at gmail.com
Sun Oct 18 01:48:46 CEST 2009


On Sat, Oct 17, 2009 at 6:15 PM, Tim Roberts <timr at probo.com> wrote:
> Toff <christophedeze at gmail.com> wrote:
>>
>>I'm trying to convert  2 c++ functions  in python
>>
>>they come from wpkg client
>>https://wpkg.svn.sourceforge.net/svnroot/wpkg/wpkg-client/Sources/Components/XmlSettings.cpp
>>
>>they are
>>CString CXmlSettings::Crypt(CString str)
>>CString CXmlSettings::Decrypt(CString str)
>>
>>CAn someone help me?
>>i d'ont know much about c++
>
> I should have tested before I posted.  These work.  There is one
> significant difference between my code and the C++ original: my code will
> not explode if the string to be encrypted is longer than 768 characters.
> Theirs will.
>
>
> key = (
>    0x50, 0xF7, 0x82, 0x69, 0xEA, 0x2D, 0xDD, 0x2D, 0x6A, 0xB4,
>    0x33, 0x8F, 0xD5, 0xC7, 0x90, 0x9C, 0x22, 0x95, 0x61, 0xE5,
>    0x65, 0xF6, 0xB0, 0x4B, 0x94, 0x47, 0xB0, 0xBD, 0x73, 0x58,
>    0x56, 0x87, 0x79, 0x7B, 0xE6, 0xB0, 0xD2, 0x20, 0x28, 0xE1
> )
>
> import base64
> import itertools
>
> def Crypt( s ):
>    return base64.b64encode(
>        ''.join(
>            chr(ord(x)^y) for x,y in itertools.izip(s,itertools.cycle(key))
>        )
>    )
>
> def Decrypt( s ):
>    s1 = base64.b64decode( s )
>    return ''.join(
>        chr(ord(x)^y) for x,y in itertools.izip(s,itertools.cycle(key))
>    )
>
> s = 'Hello, there'
> print s
> t = Crypt(s)
> print t
> u = Decrypt(t)
> print s
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

For the love of baby kittens, please, please, please tell me that
you do not believe this securely encrypts your data.

Geremy Condra



More information about the Python-list mailing list