No Huddle Offense

"Individual commitment to a group effort-that is what makes a team work, a company work, a society work, a civilization work."

RSA implemented in Python

March 31st, 2011 • Comments Off on RSA implemented in Python

Just needed to work through some algorithms lately. Best book/reference in that area is most probably the third edition of Introduction to Algorithms. Here is some python code with references to the pages in this book describing the RSA algorithm:

#!/usr/bin/python

def euclid(a, b):
    """
    Taken from page 935
    """

    if b == 0:
        return a
    else:
        return euclid(b, a % b)

def extended_euclid(a, b):
    """
    Taken form page 937
    """
    if b == 0:
        return [a, 1, 0]
    else:
        previous_d, previous_x, previous_y = extended_euclid(b, a % b)
        d, x, y = (previous_d, previous_y, previous_x - a // b * previous_y)
        return [d, x, y]

def generate_keys(p, q):
    """
    Generation of public and private keys...
    """

    n = p * q
    m = (p - 1) * (q - 1)

    e = long(2)
    while e < m:
        if euclid(e, m) == 1:
            break
        else:
            e = e + 1

    dd, x, y = extended_euclid(m, e)
    if y > 0:
        d = y
    else:
        d = y % m

    return [(e, n), (d, n)]

def rsa(p, q, msg):
    """
    RSA walkthrough - Taken from page 962
    """
    pub_key, priv_key = generate_keys(p, q)

    print 'Public Key: ', pub_key
    print 'Private Key: ', priv_key

    e, n = pub_key
    d, n = priv_key

    crypted = (msg ** e) % n
    print 'Crypted value is: ', crypted

    original = crypted ** d % n
    print 'The original number was: ', original

if __name__ == "__main__":
    p = long(raw_input('First prime: '))
    q = long(raw_input('Second prime: '))

    msg = long(raw_input('Number to test rsa with: '))

    rsa(p, q, msg)

My Software Development Environment for Python

February 21st, 2011 • Comments Off on My Software Development Environment for Python

Python is my favorite programming language for multiple reasons. Most important though is that it has a strong community, a Benevolent Dictator For Life (BDFL) and allows rapid development of high quality software. I love automation of processes wherever possible because it saves time. Here is a list of tools, methodologies, stuff I use to ensure code quality:

Tools I sometimes use during the development of code:

Thinks I would like to have replacements for:

Overall I’m pretty happy with this setup and find it good for fast coding. I usually write unittests (With test for success, failure and sanity for every routine) first before starting coding. I don’t find it a time waste but actually I’m pretty sure that the overall setup allows me to code and refactor faster.

Maybe others or you (?) also want to writeup their setups and we can start a site like The Setup for Software Development? Please Retweet and share the link!

Update: Also have a look at this Python and Dtrace blog post.

Call graphs for python

September 9th, 2010 • 1 Comment

I’m a big fan of reporting be it reports form automated builds, coverages, API documents etc. To evaluate the python code I’m currently working on I needed Call Graph for Python. After some searching and testing I found this package to be most convenient: http://pycallgraph.slowchop.com/

P.S. If you are running Ubuntu (or similar) a sudo apt-get install python-pycallgraph will install the package. To create the graph simple call: pycallgraph –include=<whatever you need> <your app.py>

A future for the world?

September 6th, 2010 • 1 Comment

Welt mit Zukunft Cover

Franz Josef Radermacher’s book about the current world situation with financial crises, natural disasters and exceeding resources not only describes the current and upcoming problems but also provides solutions towards what he calls an “eco-social market economy”. Beside the fact that the book is well written and quite short compared to the message it delivers, a good overview of what goes wrong and a possible way of solving it is presented. Only critical point would be that it doesn’t describe how we can get there. Still and definitely a book which you should read.

It describes that current established system can not solve the issue – needed is system which controls the free markets and ensure the social liability of our communities. Taxes on resources or a Supervisory Associations for financial markets which approve products before they can be sold are just one step in the right direction.

Tinkering with Illumos

September 1st, 2010 • Comments Off on Tinkering with Illumos

Honestly I do not really get the point why everybody is so upset about what happened to OpenSolaris. I can understand the steps Oracle took – and do not forget: The source is still under a CDDL license. A bit sad that the community doesn’t get real-time updates anymore.

On the other side I think that the initial idea of the Illumos project to replace the last closed source bits in ON is a good one. But I’m also looking forward to the Solaris 11 Express edition – I know some Solaris developers over at Sun/Oracle and those guys do a great job!

Here is a nice screen shot of Illumos booting BTW: