ns_crypt encrypts the key using the salt and returns the result. It uses the same algorithm as the Unix crypt command. Normally key is the user's password and salt is a two-character code used to encrypt the key.
Suppose you have a user nevsky with a password alexander. Nevsky's /etc/passwd entry might look like:
nevsky:/gteiXVtAXVqQ:28:1:Musician:/:/bin/sh
The first two characters of the encrypted password are the SALT. Since
ns_crypt /g alexander
returns /gte...Q
, then alexander is the correct password.
crypt(3) (Unix library function)