#!/usr/bin/env python

# @file  mksvnpw.py
# @brief Generates the hash of a password for the authentication to the SVN
#        repository of users outside the ENST. Inside the ENST, we use the
#        regular YP authentication.
# @note  If you are willing to choose your own salt (e.g. "XU"), the following
#        command is more convenient:
#        perl -e 'print crypt("MYPASSWORD", "XU");'
# @note  The number of possible salts is: (26+26+10+2)^2 = 4096.

import crypt;
import random;
import sys;

random.seed()

# Building the salt string of characters
def chars_between(a, b): return str.join("", map(chr, range( ord(a), ord(b)+1 )))
salt_chars= str.join("", map(chars_between, ('a','A', '0'), ('z','Z', '9'))) + "./"

# Using crypt to display a password 
salt = str.join("", [random.choice(salt_chars) for i in range(0,2)])

if len( sys.argv ) != 2: raise Exception( "Usage: %s password"%sys.argv[0] )
print crypt.crypt( sys.argv[1], salt )
