Pure Python Paillier Homomorphic Cryptosystem Implementation

What

This is a very basic Paillier Homomorphic Cryptosystem implemented in pure Python.

The idea is, in short, to encrypt two numbers, perform an "add" operation on cyphertexts, decrypt the result and find it to be the sum of the original plaintext numbers.

How

The code is loosely based on the thep project and a few ActiveState recipes. The code is pure Python and all objects are serializable.

Where

Here: https://github.com/mikeivanov/paillier

Why

I was bored.

 

Different emails for different Git repositories

On my laptop I have two directories:

  • ~/activestate, where my work projects reside, and
  • ~/me -- for my personal stuff.

The problem is, when I commit changes I want them to be properly attributed. More specifically:

  1. everything that belongs to ActiveState should be checked in using my work email
  2. all other stuff checks in with my private address
  3. I don't want to `git config user.email <...>` each time I clone a new repository ('cause I do it a lot).

Here's what I've done:

  • in my home directory I created a file called ~/.gitemail containing just my private email. This address is going to be the default
  • to the ~/activestate directory I added another .gitemail with my work address.
  • finally, I added this snippet to ~/.bashrc:
    alias git='GIT_AUTHOR_EMAIL=$(
          p=$(pwd)
          while [[ $p != "$HOME" ]]; do
            [ -e $p/.gitemail ] && cat $p/.gitemail && break
            p=$(dirname $p)
          done) /usr/bin/git'

The alias scans all the directories up to the home dir looking for a file called .gitemail. When found, it sets the GIT_AUTHOR_EMAIL variable to the file's content. This effectively makes the actual git command use the subtree-specific email. Now, when I'm working e.g. in ~/activestate/stackato, it will automatically pick up my work email from ~/activestate/.gitemail.

No extra efforts, less things to remember, and no history rewriting anymore.

 

How to mount an NTFS-formatted USB drive in read-write mode on Mac OS X

Actually, it's very easy. No additional software is required. Just seven easy steps:

  1. Attach your USB drive
  2. Open the Terminal app (Command-Space, then type "Terminal", hit Enter)
  3. Type or copy/paste this command:
    sudo sh -c "mkdir -p /mnt $(mount | grep ntfs | head -n 1 \
       | awk '{ print "&& umount " $3 " && mount_ntfs -o nosuid,rw " $1 " /mnt" }')"
  4. Locate your drive in Finder
  5. Drag/drop files there
  6. Unmount the drive as usual
  7. DONE!

The command breakdown, if you're interested:

  1. mkdir -p /mnt creates a mount point -- a place in the file system where we will attach the drive
  2. the mount command without parameters gives you a list of the currently attached drives
  3. grep ntfs filters non-ntfs drives out the list
  4. head -n 1 grabs the first line (we're assuming only one ntfs drive can be attached at a time)
  5. the awk part produces two commands:
    • umount /Volumes/<name> -- unmounts the drive from its original place
    • mount_ntfs -o nosuid,rw /dev/<device> /mnt -- mounts the drive again, but this time in the read-write mode
  6. now, the sudo sh -c "..." thing allows code execution with superuser privileges.

That's it.

Think Stats in Clojure

Recently I started looking for an opportunity to refresh my math/stats skills. I din't do this stuff for a long time, probably more than a decade; so I wanted something really basic for a refresh. Then I discovered this Think Stats book, which I'm going through right now. I find the book useful and interesting. 

To add more fun, I decided to do all the exercises from the book in Clojure instead of Python. This indeed has turned out to be a good adventure. 

My worksheets (which is a work in progress) are on Github just in case it could be it useful for someone. The project is here - https://github.com/mikeivanov/thinkstats.