C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Become a C# Expert!

Join 306,728 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,523 people online right now. Registration is fast and FREE... Join Now!





Caesar's Cipher Encryption

Encrypt a given string using Caesar's Cipher.

Submitted By: s3thst4
Actions:
Rating:
Views: 88

Language: C#

Last Modified: November 7, 2009
Instructions: Call the method with the parameters.

Snippet


  1.         public string Encrypt(string word)
  2.         {
  3.             word.ToLower();
  4.             string encryptedWord = "";
  5.             char[] split = word.ToCharArray();
  6.             foreach (char character in split)
  7.             {
  8.                 switch (character)
  9.                 {
  10.                     case 'a': encryptedWord += "d"; break;
  11.                     case 'b': encryptedWord += "e"; break;
  12.                     case 'c': encryptedWord += "f"; break;
  13.                     case 'd': encryptedWord += "g"; break;
  14.                     case 'e': encryptedWord += "h"; break;
  15.                     case 'f': encryptedWord += "i"; break;
  16.                     case 'g': encryptedWord += "j"; break;
  17.                     case 'h': encryptedWord += "k"; break;
  18.                     case 'i': encryptedWord += "l"; break;
  19.                     case 'j': encryptedWord += "m"; break;
  20.                     case 'k': encryptedWord += "n"; break;
  21.                     case 'l': encryptedWord += "o"; break;
  22.                     case 'm': encryptedWord += "p"; break;
  23.                     case 'n': encryptedWord += "q"; break;
  24.                     case 'o': encryptedWord += "r"; break;
  25.                     case 'p': encryptedWord += "s"; break;
  26.                     case 'q': encryptedWord += "t"; break;
  27.                     case 'r': encryptedWord += "u"; break;
  28.                     case 's': encryptedWord += "v"; break;
  29.                     case 't': encryptedWord += "w"; break;
  30.                     case 'u': encryptedWord += "x"; break;
  31.                     case 'v': encryptedWord += "y"; break;
  32.                     case 'w': encryptedWord += "z"; break;
  33.                     case 'x': encryptedWord += "a"; break;
  34.                     case 'y': encryptedWord += "b"; break;
  35.                     case 'z': encryptedWord += "c"; break;
  36.                 }
  37.             }
  38.             return encryptedWord;
  39.         }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month