(password, salt)
return salt[:2] + string.join(r, '')
Generate an encrypted hash from the passed password.  If the password
is longer than eight characters, only the first eight will be used.

The first two characters of the salt are used to modify the encryption
algorithm used to generate in the hash in one of 4096 different ways.
The characters for the salt should be upper- and lower-case letters A
to Z, digits 0 to 9, '.' and '/'.

The returned hash begins with the two characters of the salt, and
should be passed as the salt to verify the password.

Example:

  >>> from fcrypt import crypt
  >>> password = 'AlOtBsOl'
  >>> salt = 'cE'
  >>> hash = crypt(password, salt)
  >>> hash
  'cEpWz5IUCShqM'
  >>> crypt(password, hash) == hash
  1
  >>> crypt('IaLaIoK', hash) == hash
  0

In practice, you would read the password using something like the
getpass module, and generate the salt randomly:

  >>> import random, string
  >>> saltchars = string.letters + string.digits + './'
  >>> salt = random.choice(saltchars) + random.choice(saltchars)

Note that other ASCII characters are accepted in the salt, but the
results may not be the same as other versions of crypt.  In
particular, '_', '$1' and '$2' do not select alternative hash
algorithms such as the extended passwords, MD5 crypt and Blowfish
crypt supported by the OpenBSD C library.
Generate an encrypted hash from the passed password.  If the password
is longer than eight characters, only the first eight will be used.
Generate an encrypted hash from the passed password . If the password is longer than eight characters only the first eight will be used .
def crypt(password, salt):
    """Generate an encrypted hash from the passed password.  If the password
is longer than eight characters, only the first eight will be used.

The first two characters of the salt are used to modify the encryption
algorithm used to generate in the hash in one of 4096 different ways.
The characters for the salt should be upper- and lower-case letters A
to Z, digits 0 to 9, '.' and '/'.

The returned hash begins with the two characters of the salt, and
should be passed as the salt to verify the password.

Example:

  >>> from fcrypt import crypt
  >>> password = 'AlOtBsOl'
  >>> salt = 'cE'
  >>> hash = crypt(password, salt)
  >>> hash
  'cEpWz5IUCShqM'
  >>> crypt(password, hash) == hash
  1
  >>> crypt('IaLaIoK', hash) == hash
  0

In practice, you would read the password using something like the
getpass module, and generate the salt randomly:

  >>> import random, string
  >>> saltchars = string.letters + string.digits + './'
  >>> salt = random.choice(saltchars) + random.choice(saltchars)

Note that other ASCII characters are accepted in the salt, but the
results may not be the same as other versions of crypt.  In
particular, '_', '$1' and '$2' do not select alternative hash
algorithms such as the extended passwords, MD5 crypt and Blowfish
crypt supported by the OpenBSD C library.
"""

    # Extract the salt.
    if len(salt) == 0:
        salt = 'AA'
    elif len(salt) == 1:
        salt = salt + 'A'
    Eswap0 = _con_salt[ord(salt[0]) & 0x7f]
    Eswap1 = _con_salt[ord(salt[1]) & 0x7f] << 4

    # Generate the key and use it to apply the encryption.
    ks = _set_key((password + '\0\0\0\0\0\0\0\0')[:8])
    o1, o2 = _body(ks, Eswap0, Eswap1)

    # Extract 24-bit subsets of result with bytes reversed.
    t1 = (o1 << 16 & 0xff0000) | (o1 & 0xff00) | (o1 >> 16 & 0xff)
    t2 = (o1 >> 8 & 0xff0000) | (o2 << 8 & 0xff00) | (o2 >> 8 & 0xff)
    t3 = (o2 & 0xff0000) | (o2 >> 16 & 0xff00)
    # Extract 6-bit subsets.
    r = [ t1 >> 18 & 0x3f, t1 >> 12 & 0x3f, t1 >> 6 & 0x3f, t1 & 0x3f,
          t2 >> 18 & 0x3f, t2 >> 12 & 0x3f, t2 >> 6 & 0x3f, t2 & 0x3f,
          t3 >> 18 & 0x3f, t3 >> 12 & 0x3f, t3 >> 6 & 0x3f ]
    # Convert to characters.
    for i in xrange(len(r)):
        r[i] = _cov_2char[r[i]]
    return salt[:2] + string.join(r, '')
def crypt ( password , salt ) : # Extract the salt. if len ( salt ) == 0 : salt = 'AA' elif len ( salt ) == 1 : salt = salt + 'A' Eswap0 = _con_salt [ ord ( salt [ 0 ] ) & 0x7f ] Eswap1 = _con_salt [ ord ( salt [ 1 ] ) & 0x7f ] << 4 # Generate the key and use it to apply the encryption. ks = _set_key ( ( password + '\0\0\0\0\0\0\0\0' ) [ : 8 ] ) o1 , o2 = _body ( ks , Eswap0 , Eswap1 ) # Extract 24-bit subsets of result with bytes reversed. t1 = ( o1 << 16 & 0xff0000 ) | ( o1 & 0xff00 ) | ( o1 >> 16 & 0xff ) t2 = ( o1 >> 8 & 0xff0000 ) | ( o2 << 8 & 0xff00 ) | ( o2 >> 8 & 0xff ) t3 = ( o2 & 0xff0000 ) | ( o2 >> 16 & 0xff00 ) # Extract 6-bit subsets. r = [ t1 >> 18 & 0x3f , t1 >> 12 & 0x3f , t1 >> 6 & 0x3f , t1 & 0x3f , t2 >> 18 & 0x3f , t2 >> 12 & 0x3f , t2 >> 6 & 0x3f , t2 & 0x3f , t3 >> 18 & 0x3f , t3 >> 12 & 0x3f , t3 >> 6 & 0x3f ] # Convert to characters. for i in xrange ( len ( r ) ) : r [ i ] = _cov_2char [ r [ i ] ] return salt [ : 2 ] + string . join ( r , '' )