usingSystem;classMainClass{publicstaticvoidMain(string[]args){varcaesarCipher=newCaesarCipher();caesarCipher.Encrypt(3,"attack from the woods at dawn");}}publicclassCaesarCipher{publicvoidEncrypt(intkey,stringtext){if(key<1||key>26){thrownewException("Key must be between 1 and 26 inclusive.");}Console.WriteLine("Plain:");Console.WriteLine(text);vardecText=newchar[text.Length];for(inti=0;i<text.Length;i++){intdec=(int)text[i];if(dec>=65&&dec<=90||dec>=97&&dec<=122){decText[i]=(char)(dec+key);}else{decText[i]=(char)dec;}}Console.WriteLine("Encrypted:");Console.WriteLine(decText);}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
C#
Rept.it