Archive for the ‘python’ Category

A cryptographic tool that converts weak password into a strong password before encrypting

Here’s a small encryption/decryption tool that works based on AES algorithm. No matter how weak your password is, the program converts it to a  32 digits hexadecimal number  before encrypting. This is achieved by finding the MD5 hash of the password using hashlib python module. This hash is used to encrypt the file.

The source file is here

The idea in my mind while writing this program was this:

Suppose a cracker gets an encrypted file and he figures out it’s encrypted using AES somehow. Then he starts brute force attack on it to find the key and extract information. If the password used to encrypt that file is weak and if it’s based on a dictionary word, the cracker can easily figure out the password. Hence the password  given by the user must be made stronger by the encrypting program. And the best way to make a password strong is by using  digest algorithms since it’s unique to a string.

What do you think? Am I wrong? Thank you 🙂


A small and simple note taking app

Wrote a small python script that can be used with your favorite text editor as a simple note taking application. Hope you like it, suggestions are always welcome 🙂

Here’s the code!

Thank you 🙂

The little twitter client I use :)

Here’s a small python script to update and read tweets from different timelines. You can use it with head/tail commands to customize the output. Actually, I wrote this script just for personal use and now I would like to share it with you 🙂 Thanks to tweepy python module, make sure it’s installed before trying the script 🙂

#!/usr/bin/env python
# Copyright 2011 Ershad K <ershad92@[nospam]>
# Licensed under GPL Version 3

import sys
import tweepy

CONSUMER_KEY = ' Fill here'
CONSUMER_SECRET = ' File here too'
ACCESS_KEY = ' Type yours here'
ACCESS_SECRET = 'Type yours here too'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

if sys.argv[1] == 'u':

elif sys.argv[1] == 'p':
    public_tweets = api.public_timeline()
    for tweet in public_tweets:
        print tweet.user.screen_name,":",tweet.text
        print ""

elif sys.argv[1] == 'r':
    mention_tweets = api.mentions()
    for mtweet in mention_tweets:
        print mtweet.user.screen_name,":",mtweet.text
        print ""

elif sys.argv[1] == 'h':
    friends_tweets = api.home_timeline()
    for ftweet in friends_tweets:
        print ftweet.user.screen_name,":", ftweet.text
        print ""

Hope you like it 🙂

Python Script to fix VBR errors of mp3 files in a directory, recursively

February 19, 2011 8 comments

If the seek bar of your rhythmbox is not working with some mp3 files, it might be an issue with Variable Bit Rate of them. The tool, ‘vbrfix’ written by William Pye solves the issue, but the problem is that it doesn’t have an option to search for files recursively. Here is a small python script that gets the paths of multiple mp3 files recursively and give them as arguments to vbrfix tool. Make sure you install vbrfix (from the software repo) before running the script.

Please see comments for a better, 1 line substitute to do the same. Thanks to Rajeesh ettan and Syam ettan 🙂

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#       Copyright 2011 Ershad K <>     
#       Usage: python
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       GNU General Public License for more details.
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import sys
import os

quote = '"'
folder = sys.argv[1]
find_command = "find " + folder
find_command += " > mp3files_list"

os.system("sed 1d mp3files_list > mp3files_list1");

f = open("mp3files_list1", 'r')
for line in f:
    line = line[:len(line)-1]
    command = "vbrfix -always "
    command += quote + line + quote
    command += " " + quote + line + quote
    print command

os.system("rm mp3files_list mp3files_list1")

Improvements to code and suggestions are always welcome, Happy Hacking 🙂

Python Script to backup tweets

It was some conversations in Twitter with @aashiks and @geohacker that made me write this script. The conversation goes like this:

geohacker : What is the best way to archive my twitter timeline?
            I think I'm loosing several precious tweets! #help #please
ershus    : Copy-paste ? ;)
aashiks   : @geohacker ask @ershus to write a python script and
            retrieve data using the twitter api
ershus    : @aashiks My god! ഞാന്‍ ഒന്നും പറഞ്ഞില്ല ! ദയവായ് ക്ഷമിക്കൂ.....
            PS: വിടാന്‍ ഉദ്ദേശമില്ല, ശ്രമിക്കാം :) ( @geohacker )
aashiks   : @geohacker - kandallo ? thats how you do it :D
            @ershus vegam V0.1 erakku :D

Well, this little script is born! Thanks to them, else I would not have written anything like this.

This is my first ‘working’ python script and I’m very happy to share with you. I’ve just started using python,  you may be able to suggest a lot of improvements in the code. Please help me by pointing out the mistakes and other suggestions.

This script uses python-twitter library,  please make sure it’s installed before running the code.

Thanks to Rajeesh ettan who helped me with unicode issues and time.sleep() 🙂

Here’s the code:

#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Version 1.0
# Copyright (C) 2010 - Ershad K
# Licensed under GPL Version 3

import os, sys, codecs
import time
import twitter

# Change the following values
username = 'USERNAME'
password = 'PASSWORD'
backup_file = 'twitterbackfile' #File name or Path + File name
sleep_time = 5 #seconds

fout =, 'a') #to create such a file
api = twitter.Api(username, password)

while (True):
	timeline = api.GetFriendsTimeline(username)
	for s in timeline:
		#print "%s\t%s" % (, s.text)
		tweet = + "\t" + s.text
		fin = open(backup_file, 'r')
		x =
		y = x.find(tweet.encode("utf-8"))

		if y < 0:
			fout =, 'a')
			text = + "\t" + s.text + "\n"

Thank you 🙂