You are viewing a single comment's thread. Return to all comments →
C# Note: upperAlpha isn't necessary, just use lowerAlpha.ToUpper() in place as necessary, or define it as such.
public static string caesarCipher(string s, int k) { char[] encrypted = s.ToCharArray(); char[] lowerAlpha = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); char[] upperAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); for (int letter = 0; letter < encrypted.Length; letter++){ if (lowerAlpha.Contains(encrypted[letter])) encrypted[letter] = lowerAlpha[ ((Array.IndexOf(lowerAlpha, encrypted[letter]) + k) % 26)]; else if (upperAlpha.Contains(encrypted[letter])) encrypted[letter] = upperAlpha[ (( Array.IndexOf(upperAlpha, encrypted[letter]) + k) % 26)]; } string final = ""; foreach (char i in encrypted){ final += i; } return final; }
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
C# Note: upperAlpha isn't necessary, just use lowerAlpha.ToUpper() in place as necessary, or define it as such.