Example #1
0
        /*
         * The key for nihilist cipher has 2 components: the key for the polybius square, and the key for encryption, split by the character ~.
         * If either one has characters not contained by the polybius square, the string is invalid.
         */
        protected override CipherKey CheckKeyValidity(String key)
        {
            CipherKey cipherKey = new CipherKey();
            String    polybiusSquareKey, encryptionKey;

            String[] temp = key.Split('~');
            if (temp.Length != 2)
            {
                throw new InvalidKeyFormatException("The key introduced for the nihilist cipher doesn't respect the input format: {polybius square key}~{encryption key}");
            }
            polybiusSquareKey = temp[0];
            encryptionKey     = temp[1];

            for (int i = 0; i < polybiusSquareKey.Length; i++)
            {
                if (!MyPolybiusSquare.ContainsCharacter(polybiusSquareKey[i]))
                {
                    throw new InvalidKeyFormatException("The key introduced for the nihilist cipher for the polybius square contains more than the permitted characters!");
                }
            }

            for (int i = 0; i < encryptionKey.Length; i++)
            {
                if (!MyPolybiusSquare.ContainsCharacter(encryptionKey[i]))
                {
                    throw new InvalidKeyFormatException("The key introduced for the nihilist cipher for encryption contains more than alphabet letters!");
                }
            }

            cipherKey.SetStringValue(encryptionKey);
            return(cipherKey);
        }
Example #2
0
        /*
         * Checks if the string is only formed of an integer, otherwise throws an exception.
         */
        protected override CipherKey CheckKeyValidity(String key)
        {
            CipherKey cipherKey = new CipherKey();

            if (key.Equals("") || !int.TryParse(key, out int tempKey))
            {
                throw new InvalidKeyFormatException("The key introduced for the caesar cipher is not an integer!");
            }
            cipherKey.SetNumericalValue(tempKey % 26);
            return(cipherKey);
        }
Example #3
0
        /*
         * Checks if the key string contains characters contained by the polybius square.
         */
        protected override CipherKey CheckKeyValidity(String key)
        {
            CipherKey cipherKey = new CipherKey();

            for (int i = 0; i < key.Length; i++)
            {
                if (!MyPolybiusSquare.ContainsCharacter(key[i]))
                {
                    throw new InvalidKeyFormatException("The key introduced for the bifid cipher contains more than the permitted characters!");
                }
            }

            cipherKey.SetStringValue(key);
            return(cipherKey);
        }