private static string Cipher(string key, string str, ShiftMethod shiftMethod) { var encryptedText = ""; var keyIndex = 0; foreach (var symbol in str) { if (!Alphabet.Contains(symbol.ToString())) { encryptedText += symbol; continue; } var shiftedIndex = shiftMethod(key[keyIndex], symbol); keyIndex++; if (keyIndex == key.Length) { keyIndex = 0; } if (char.IsUpper(symbol)) { encryptedText += char.ToUpper(Alphabet[shiftedIndex]); } else { encryptedText += Alphabet[shiftedIndex]; } } return(encryptedText); }
public string Encrypt(string key, string str) { ShiftMethod shiftMethod = CalculateShiftForEncryption; return(Cipher(key, str, shiftMethod)); }