Day: March 28, 2005

  • Python for Series 60 Crypto: DES

    Pure Python DES module

    Speaking of pure python crypto, it looks like PyDES works perfectly too. This one will probably require bits of the Python 2.2.2 source in order to run though. Specifically it’s looking for binascii and time. All in all it’s quite lightweight and seems more responsive in both import time and encrypt/decrypt time as compared to It’s still very slow compared to a native implementation, but should be fast enough for inclusion in Python for Series 60 apps.

    DES and 3DES are available from this module. I can’t seem to find a reference to what license it is released under, so you might want to track down the author before writing an application around it.

    Here’s the code for the demo above (taken from an example that ships with PyDES):

    import pyDes
    k = pyDes.des("DESCRYPT", pyDes.CBC, "")
    print "Encrypting/Decrypting DES"
    d = k.encrypt("Please encrypt my string")
    print "Decypted string: " + k.decrypt(d)
    k = pyDes.triple_des("MySecretTripleDesKeyData")
    print "Encrypting/Decrypting 3DES"
    d = k.encrypt("Encrypt this sensitive data", "*")
    print "Decypted string: " + k.decrypt(d, "*")

  • Blowfish in Your Pocket

    Blowfish on Python for Series 60

    After finding out how well BeautifulSoup worked on my N-Gage, I decided to try to find more modules that “just worked” on Python for Series 60. First up is, a project by Michael Gilfix. The file itself is not available directly from the author within the US, but Google cache can help with that.

    The module is pure python, with absolutely no module dependencies. I have only tested it on the MMC with the full Python distribution on it, but this one (in theory) should work on a stock .SIS install without any addition python modules in your libs directory. It’s definitely not fast by any stretch of the imagination, but it may be a good building block if you want to add some crypto to your mobile application.

    Here is the code that is being executed in the screen shot above:

    import blowfish
    key = 'hey, look over there!'
    print 'generating the fish'
    fish = blowfish.Blowfish(key)
    print 'Plaintext:'
    text = 'testtest'
    print text
    print 'Encrypting...'
    crypted = fish.encrypt(text)
    print 'Encrypted.'
    # Printing encrypted chars causes barf
    print 'Decrypting...'
    decrypted = fish.decrypt(crypted)
    print 'Decrypted:'
    print decrypted


  • PyCon Nugget: shpy

    One of the lightning talks from day 2 of PyCon that wowed me the most was the demo of shpy. I was really bummed when I tried to hop online just to find out that codespeak was down, but the site is back up now.

    Shpy is like a poor man’s (read: non-Mac) SubEthaEdit. The analogy isn’t exact though. Shpy is really a text editor designed for writing Python code that can be edited by multiple people simultaneously with no noticeable lag for each end user. The document is kept in sync on a line-by-line basis so that you only run in to problems when mutliple people are editing the same line at once, which isn’t as rare an occurance as you might think.

    The fun doesn’t stop there though. Shpy also allows for the execution of Python code from within the editor, hence the name. I was really impressed and can’t wait to give it a go. It might even get interesting if I combine shpy with screen over ssh to keep a todo.txt (er always (or just a ssh session away anyway) available.

    For more information, check out the shpy documentation.

  • Mobile Screen Scraping with BeautifulSoup and Python for Series 60

    BeautifulSoup 2 BeautifulSoup 3

    I haven’t had enough time to work up a proper hack for this, but I though I would pass along an interesting discovery that I made the other day before heading out to PyCon. After hearing about how great BeautifulSoup is at scraping HTML and making it easy to get little bits from it that you need, I thought I’d have a go at running it on my taco. You know what? It worked. I was expecting it to barf on import, but no, it chugged along just fine.

    Now unfortunately BeautifulSoup won’t work out of the box with the standard .SIS install of Python for Series 60. It relies only on SGMLParser, string, and types, but those three libraries have some dependencies themselves. Here is what BeautifulSoup requires according to running on my Debian box:

    • array
    • copy_reg
    • markupbase
    • re
    • sgmllib
    • sre
    • sre_compile
    • sre_constraints
    • sre_parse
    • string
    • strop
    • sys
    • types

    These dependencies can be easily taken care of by dropping the python modules from the source distro in the appropriate libs directory on the drive you installed Python on.

    One reason that BeautfulSoup “just works” on Series 60 is that the author strives to keep imports to a minimum and that the author srives to keep BeautifulSoup backwards compatible all the way back to Python 1.5.2. There are probably many modules out there like BeautifulSoup that are designed to be backwards compatible and platform independent that should work just fine on Series 60. As I find them, I will definitely point them out. I also hope to do some hacking on a few screen scraping apps that use BeautifulSoup and appuifw to present web data using native widgets.