Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _7.DecodeAndEncodeText
- {
- class DecodeAndEncodeText
- {
- static void Main()
- {
- //Console.WriteLine("Enter a string:");
- //string str = Console.ReadLine();
- //Console.WriteLine("Enter a cipfer:");
- //string cipfer = Console.ReadLine();
- string str = "racho reje riba i petar plet plete";
- string cipfer = "key";
- //Encryption
- StringBuilder encryption = new StringBuilder();
- for (int i = 0, cipfCounter = 0; i < str.Length; i++ , cipfCounter++)
- {
- encryption.Append((char)((int)str[i] ^ (int)cipfer[cipfCounter]));
- if (cipfCounter + 1 == cipfer.Length)
- {
- cipfCounter = 0;
- }
- }
- string encryptedString = encryption.ToString();
- Console.WriteLine("The encrypted string is:");
- Console.WriteLine(encryptedString);
- //Encryption
- StringBuilder decryption = new StringBuilder();
- for (int i = 0, cipfCounter = 0; i < encryptedString.Length; i++, cipfCounter++)
- {
- decryption.Append((char)((int)encryptedString[i] ^ (int)cipfer[cipfCounter]));
- if (cipfCounter + 1 == cipfer.Length)
- {
- cipfCounter = 0;
- }
- }
- Console.WriteLine("The decrypted string is:");
- Console.WriteLine(decryption.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement