public Caesar(int key) { foreach (char letter in DEFAULT_ALPHABET) { char encodedLetter = DEFAULT_ALPHABET[(DEFAULT_ALPHABET.IndexOf(letter) + key) % DEFAULT_ALPHABET.Count]; EncodeAlphabet.Add(letter, encodedLetter); DecodeAlphabet.Add(encodedLetter, letter); } }
public Caesar(string wordKey, int key) { IEnumerable <char> wordKeyUnique = wordKey .ToLower() .ToCharArray() .Where(letter => char.IsLetter(letter)) .Distinct(); int keySize = wordKeyUnique.Count(); IEnumerable <char> other = DEFAULT_ALPHABET.Except(wordKeyUnique); char[] encodeAlphabet = other .Skip(DEFAULT_ALPHABET.Count - key - keySize) .Concat(wordKeyUnique) .Concat(other.Take(DEFAULT_ALPHABET.Count - key - keySize)) .ToArray(); for (int i = 0; i < DEFAULT_ALPHABET.Count; ++i) { EncodeAlphabet.Add(DEFAULT_ALPHABET[i], encodeAlphabet[i]); DecodeAlphabet.Add(encodeAlphabet[i], DEFAULT_ALPHABET[i]); } }