fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. String plainAlphabet = "abcdefghijklmnopqrstuvwxyz";
  8. String cipherAlphabet = "zyxwvutsrqponmlkjihgfedcba";
  9. String text = "Some sensitive text that only humans must be able to read";
  10.  
  11. String encodedText = encrypt(plainAlphabet, cipherAlphabet, text);
  12. Console.WriteLine(encodedText);
  13. }
  14.  
  15. public static String encrypt(String plain, String cipher, String text) {
  16. plain = plain + plain.ToUpper();
  17. cipher = cipher + cipher.ToUpper();
  18.  
  19. String newText = "";
  20. for(int i=0; i<text.Length; i++) {
  21. char c = text[i];
  22. int index = plain.IndexOf(c);
  23. if(index >= 0 && index < cipher.Length) {
  24. newText += cipher[index];
  25. } else {
  26. newText += c;
  27. }
  28. }
  29. return newText;
  30. }
  31. }
Success #stdin #stdout 0.04s 24176KB
stdin
Standard input is empty
stdout
Hlnv hvmhrgrev gvcg gszg lmob sfnzmh nfhg yv zyov gl ivzw