Advertisement
petromaxa

Untitled

Jan 31st, 2013
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _7.DecodeAndEncodeText
  7. {
  8. class DecodeAndEncodeText
  9. {
  10. static void Main()
  11. {
  12. //Console.WriteLine("Enter a string:");
  13. //string str = Console.ReadLine();
  14. //Console.WriteLine("Enter a cipfer:");
  15. //string cipfer = Console.ReadLine();
  16.  
  17. string str = "racho reje riba i petar plet plete";
  18. string cipfer = "key";
  19. //Encryption
  20. StringBuilder encryption = new StringBuilder();
  21. for (int i = 0, cipfCounter = 0; i < str.Length; i++ , cipfCounter++)
  22. {
  23. encryption.Append((char)((int)str[i] ^ (int)cipfer[cipfCounter]));
  24. if (cipfCounter + 1 == cipfer.Length)
  25. {
  26. cipfCounter = 0;
  27. }
  28. }
  29. string encryptedString = encryption.ToString();
  30. Console.WriteLine("The encrypted string is:");
  31. Console.WriteLine(encryptedString);
  32.  
  33. //Encryption
  34. StringBuilder decryption = new StringBuilder();
  35. for (int i = 0, cipfCounter = 0; i < encryptedString.Length; i++, cipfCounter++)
  36. {
  37. decryption.Append((char)((int)encryptedString[i] ^ (int)cipfer[cipfCounter]));
  38. if (cipfCounter + 1 == cipfer.Length)
  39. {
  40. cipfCounter = 0;
  41. }
  42. }
  43. Console.WriteLine("The decrypted string is:");
  44. Console.WriteLine(decryption.ToString());
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement