using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Ex06_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string Encrypt(string s)
        {
            Encoding ascii = Encoding.Default;
            string EncryptString;
            EncryptString = "";
            for (int i = 0; i < s.Length; i++)
            {
                int j;
                byte[] b = new byte[1];
                j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
                j = j + 1;
                b[0] = Convert.ToByte(j);
                EncryptString = EncryptString + ascii.GetString(b);
            }
            return EncryptString;
        }

        private string Decryptor(string s)
        {
            Encoding ascii = Encoding.Default;
            string DecryptorString;
            DecryptorString = "";
            for (int i = 0; i < s.Length; i++)
            {
                int j;
                byte[] b = new byte[1];
                j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
                j = j - 1;
                b[0] = Convert.ToByte(j);
                DecryptorString = DecryptorString + ascii.GetString(b);
            }
            return DecryptorString;
        }


        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = Encrypt(richTextBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            this.openFileDialog1.ShowDialog();
            StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);
            richTextBox1.Text = sr.ReadToEnd();
            sr.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = Decryptor(richTextBox1.Text);
        }
    }
}
