Exemplo n.º 1
0
/**
 * encihper()
 * p:   Position of plain-text character (assumes it is a char) [in]
 * k:   Position of key character (assumes it is a char)        [in]
 *
 * Returns values of table[p+k] for encryption.
 **/
char VC::encipher(char p, char k){
        // Index counters for both plain-text and key characters
        int pn = 0, kn = 0;

        pn = tbl_lookup(p);
        kn = tbl_lookup(k);

        int i = pn + kn;

        // Since table is base-0, we need to make sure we're still in the bounds of MODULO
        while(i >= MODULO){
                i -= MODULO;
        }

        return table[i];
}
Exemplo n.º 2
0
/**
 * decipher()
 * c:   Cipher character        [in]
 * k:   Key character           [in]
 *
 * Decrypts a cipher back to plain text.
 *
 * Same thing as encipher() basically, except for it subtracts pn and kn.
 **/
char VC::decipher(char c, char k){
        // Index counters for both cipher and key characters
        int cn = 0, kn = 0;

        cn = tbl_lookup(c);
        kn = tbl_lookup(k);

        /**
         * table[index] = cipher_index - key_index
         *
         * Unlike in encipher(), due to math theorems, substitution MUST be this way.
         **/
        int i = cn - kn;

        if(i < 0)
                i += MODULO;

        return table[i];
}
Exemplo n.º 3
0
int
nnpfs_dnlc_lookup(struct vnode *dvp,
		nnpfs_componentname *cnp,
		struct vnode **res)
{
    int error = nnpfs_dnlc_lookup_int (dvp, cnp, res);

    if (error == 0)
	error = tbl_lookup (cnp, dvp, res);

    if (error != -1)
	return error;

    return nnpfs_dnlc_lock (dvp, cnp, res);
}
Exemplo n.º 4
0
int
xfs_dnlc_lookup(struct vnode *dvp,
		xfs_componentname *cnp,
		struct vnode **res)
{
    int error = xfs_dnlc_lookup_int (dvp, cnp, res);

    if (error == 0)
	return -1;
    else if (error == ENOENT)
	return error;

    error = tbl_lookup (cnp, dvp, res);

    if (error != -1)
	return error;

    return xfs_dnlc_lock (dvp, cnp, res);
}