All pastes #619810 Raw Edit

xorcrypt

public text v1 · immutable
·published 2007-07-15 01:10 UTC
rendered paste body
namespace xorcrypt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            string hexsequence = "\"", rRef = "0x", plain = rtbPlainText.Text, cipher;
            int chval, startval = r.Next(256), xval = startval;

            for (int i = 0; i < 4; i++)
                rRef += r.Next(256).ToString("X");

            for (int i = 0; i < plain.Length; i++)
            {
                if(plain[i] == '\\')
                {
                    i++;
                    if(plain[i] == '0') chval = 0;
                    else if (plain[i] == 'n') chval = 10;
                    else if (plain[i] == '\\') chval = 92;
                    else if (plain[i] == 'r') chval = 13;
                    else rtbCipherText.Text = String.Format("Invalid Character {0}", plain[i]); return;
                }
                else if (plain[i] == '|') chval = 0;
                else 
                {
                    chval = (int)plain[i];
                    if( (chval < 32) || (chval > 126))
                        rtbCipherText.Text = String.Format("Invalid Character {0}", plain[i]); return;
                }

                chval ^= xval;
                xval += 1;
                xval %= 256;
                hexsequence += "\\x" + chval.ToString("X");
            }

            hexsequence += "\"";

            cipher = "/*" + plain + "*/ XorStr<0x" + startval.ToString("X") + ",";
            cipher += String.Format("{0}",plain.Length+1) + "," +rRef + ">(" + hexsequence + "+" + rRef + ").s";

            rtbCipherText.Text = cipher;
        }
    }
}