Jump to content

[C#] Review my code?


TheDespite
 Share

Recommended Posts

Hello. I lately decided to move on from php and learn some C# and C++.

I've been creating a couple of these test projects, and here is my latest one.

 

Simply what I tried to create, was a program that would allow one to code and decode a string with a password, making anyone without the password unable to read it.

It works rather well, but the code is not optimized, and I used like 9999 strings. Please do not comment this, but prehaps point me to the right way with While loops prehaps?

 

Here's the actual functions (the whole project and compiled program below)

	    private void textBox6_TextChanged(object sender, EventArgs e)
    {
	    solvechanged();
    }

    private void hidechanged()
    {
	    if (textBox1.Text == "" || textBox2.Text == "")
	    { }

	    else
	    {
		    string todissolve1 = textBox1.Text;
		    string topass1 = textBox2.Text;

		    string topassa = topass1.Replace("a", "1");
		    string topassb = topassa.Replace("b", "2");
		    string topassc = topassb.Replace("c", "3");
		    string topassd = topassc.Replace("d", "4");
		    string topasse = topassd.Replace("e", "5");
		    string topassf = topasse.Replace("f", "6");
		    string topassg = topassf.Replace("g", "7");
		    string topassh = topassg.Replace("h", "8");
		    string topassi = topassh.Replace("i", "9");
		    string topassj = topassi.Replace("j", "10");
		    string topassk = topassj.Replace("k", "11");
		    string topassl = topassk.Replace("l", "12");
		    string topassm = topassl.Replace("m", "13");
		    string topassn = topassm.Replace("n", "14");
		    string topasso = topassn.Replace("o", "15");
		    string topassp = topasso.Replace("p", "16");
		    string topassq = topassp.Replace("q", "17");
		    string topassr = topassq.Replace("r", "18");
		    string topasss = topassr.Replace("s", "19");
		    string topasst = topasss.Replace("t", "20");
		    string topassu = topasst.Replace("u", "21");
		    string topassv = topassu.Replace("v", "22");
		    string topassw = topassv.Replace("w", "23");
		    string topassx = topassw.Replace("x", "24");
		    string topassy = topassx.Replace("y", "25");
		    string topassz = topassy.Replace("z", "26");

		    long pass = long.Parse(topassz);

		    string todissolvea = todissolve1.Replace("a", string.Concat(2 * pass));
		    string todissolveb = todissolvea.Replace("b", string.Concat(3 * pass));
		    string todissolvec = todissolveb.Replace("c", string.Concat(5 * pass));
		    string todissolved = todissolvec.Replace("d", string.Concat(7 * pass));
		    string todissolvee = todissolved.Replace("e", string.Concat(11 * pass));
		    string todissolvef = todissolvee.Replace("f", string.Concat(13 * pass));
		    string todissolveg = todissolvef.Replace("g", string.Concat(17 * pass));
		    string todissolveh = todissolveg.Replace("h", string.Concat(19 * pass));
		    string todissolvei = todissolveh.Replace("i", string.Concat(23 * pass));
		    string todissolvej = todissolvei.Replace("j", string.Concat(29 * pass));
		    string todissolvek = todissolvej.Replace("k", string.Concat(31 * pass));
		    string todissolvel = todissolvek.Replace("l", string.Concat(37 * pass));
		    string todissolvem = todissolvel.Replace("m", string.Concat(41 * pass));
		    string todissolven = todissolvem.Replace("n", string.Concat(43 * pass));
		    string todissolveo = todissolven.Replace("o", string.Concat(47 * pass));
		    string todissolvep = todissolveo.Replace("p", string.Concat(53 * pass));
		    string todissolveq = todissolvep.Replace("q", string.Concat(59 * pass));
		    string todissolver = todissolveq.Replace("r", string.Concat(61 * pass));
		    string todissolves = todissolver.Replace("s", string.Concat(67 * pass));
		    string todissolvet = todissolves.Replace("t", string.Concat(71 * pass));
		    string todissolveu = todissolvet.Replace("u", string.Concat(73 * pass));
		    string todissolvev = todissolveu.Replace("v", string.Concat(79 * pass));
		    string todissolvew = todissolvev.Replace("w", string.Concat(83 * pass));
		    string todissolvex = todissolvew.Replace("x", string.Concat(89 * pass));
		    string todissolvey = todissolvex.Replace("y", string.Concat(97 * pass));
		    string todissolvez = todissolvey.Replace("z", string.Concat(101 * pass));

		    string dissolved = todissolvez;

		    textBox3.Text = dissolved;

		    if (textBox3.Text != "" && checkBox1.Checked)
			    Clipboard.SetText(textBox3.Text);
	    }
    }

    private void solvechanged()
    {
	    if (textBox4.Text == "" || textBox6.Text == "")
	    { }
	    else
	    {

		    string tosolve1 = textBox4.Text;
		    string topass21 = textBox6.Text;

		    string topass2a = topass21.Replace("a", "1");
		    string topass2b = topass2a.Replace("b", "2");
		    string topass2c = topass2b.Replace("c", "3");
		    string topass2d = topass2c.Replace("d", "4");
		    string topass2e = topass2d.Replace("e", "5");
		    string topass2f = topass2e.Replace("f", "6");
		    string topass2g = topass2f.Replace("g", "7");
		    string topass2h = topass2g.Replace("h", "8");
		    string topass2i = topass2h.Replace("i", "9");
		    string topass2j = topass2i.Replace("j", "10");
		    string topass2k = topass2j.Replace("k", "11");
		    string topass2l = topass2k.Replace("l", "12");
		    string topass2m = topass2l.Replace("m", "13");
		    string topass2n = topass2m.Replace("n", "14");
		    string topass2o = topass2n.Replace("o", "15");
		    string topass2p = topass2o.Replace("p", "16");
		    string topass2q = topass2p.Replace("q", "17");
		    string topass2r = topass2q.Replace("r", "18");
		    string topass2s = topass2r.Replace("s", "19");
		    string topass2t = topass2s.Replace("t", "20");
		    string topass2u = topass2t.Replace("u", "21");
		    string topass2v = topass2u.Replace("v", "22");
		    string topass2w = topass2v.Replace("w", "23");
		    string topass2x = topass2w.Replace("x", "24");
		    string topass2y = topass2x.Replace("y", "25");
		    string topass2z = topass2y.Replace("z", "26");

		    long pass2 = long.Parse(topass2z);

		    string tosolvea = tosolve1.Replace(string.Concat(2 * pass2), "a");
		    string tosolveb = tosolvea.Replace(string.Concat(3 * pass2), "b");
		    string tosolvec = tosolveb.Replace(string.Concat(5 * pass2), "c");
		    string tosolved = tosolvec.Replace(string.Concat(7 * pass2), "d");
		    string tosolvee = tosolved.Replace(string.Concat(11 * pass2), "e");
		    string tosolvef = tosolvee.Replace(string.Concat(13 * pass2), "f");
		    string tosolveg = tosolvef.Replace(string.Concat(17 * pass2), "g");
		    string tosolveh = tosolveg.Replace(string.Concat(19 * pass2), "h");
		    string tosolvei = tosolveh.Replace(string.Concat(23 * pass2), "i");
		    string tosolvej = tosolvei.Replace(string.Concat(29 * pass2), "j");
		    string tosolvek = tosolvej.Replace(string.Concat(31 * pass2), "k");
		    string tosolvel = tosolvek.Replace(string.Concat(37 * pass2), "l");
		    string tosolvem = tosolvel.Replace(string.Concat(41 * pass2), "m");
		    string tosolven = tosolvem.Replace(string.Concat(43 * pass2), "n");
		    string tosolveo = tosolven.Replace(string.Concat(47 * pass2), "o");
		    string tosolvep = tosolveo.Replace(string.Concat(53 * pass2), "p");
		    string tosolveq = tosolvep.Replace(string.Concat(59 * pass2), "q");
		    string tosolver = tosolveq.Replace(string.Concat(61 * pass2), "r");
		    string tosolves = tosolver.Replace(string.Concat(67 * pass2), "s");
		    string tosolvet = tosolves.Replace(string.Concat(71 * pass2), "t");
		    string tosolveu = tosolvet.Replace(string.Concat(73 * pass2), "u");
		    string tosolvev = tosolveu.Replace(string.Concat(79 * pass2), "v");
		    string tosolvew = tosolvev.Replace(string.Concat(83 * pass2), "w");
		    string tosolvex = tosolvew.Replace(string.Concat(89 * pass2), "x");
		    string tosolvey = tosolvex.Replace(string.Concat(97 * pass2), "y");
		    string tosolvez = tosolvey.Replace(string.Concat(101 * pass2), "z");

		    string solved = tosolvez;

		    if (solved == tosolve1 && solved != "" && checkBox3.Checked)
			    MessageBox.Show("The key entered was invalid for the string entered. The output will be the same as the input.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

		    textBox5.Text = solved;

		    if (textBox5.Text != "" && checkBox2.Checked)
		    {
			    Clipboard.SetText(solved);
		    }
	    }
    }

 

I'd love any information on how easy the coded string would be to brute force crack.

Also if you have any suggestions what should I experiment with on my next program, please do share!

Project (I wasn't allowed to post rar as an attachment)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...