Advertising (This ad goes away for registered users. You can Login or Register)

Help debugging?

Programming on your favorite platform, for your favorite platform? Post here
Locked
Nickolas
Posts: 174
Joined: Sat Jan 22, 2011 3:14 pm
Location: In a black hole...

Help debugging?

Post by Nickolas »

I am either too tired or too dumb, but I don't see what's wrong here... This is my code. It returns the original value of "text".

Code: Select all

using System;
namespace UniHash
{
	public class Encryption
	{
		public static string Encrypt(string text)
		{
			text.Replace ("a ", "tor^y");
			text.Replace ("b", "k6a");
			text.Replace ("c", "taf9i");
			text.Replace ("d", "po");
			text.Replace ("e", "t67b");
			text.Replace ("f", "-lod;");
			text.Replace ("g", "2wr5");
			text.Replace ("h", "7ghf");
			text.Replace ("i", "4r");
			text.Replace ("j", "mopc");
			text.Replace ("k", "76ds");
			text.Replace ("l", "vedf@");
			text.Replace ("m", "gf&tf");
			text.Replace ("n", "te-d");
			text.Replace ("o", "te5g");
			text.Replace ("p", "jk");
			text.Replace ("q", "3wcb");
			text.Replace ("r", "kard");
			text.Replace ("s", "8gt");
			text.Replace ("t", "pokj");
			text.Replace ("u", "2fer");
			text.Replace ("v", "zec");
			text.Replace ("w", "artuo");
			text.Replace ("x", "gitg");
			text.Replace ("y", "ret5");
			text.Replace ("z", "peji");
			text.Replace ("A", "rgds");
			text.Replace ("B", "klhs");
			text.Replace ("C", "trgd");
			text.Replace ("D", "375d");
			text.Replace ("E", "hggs");
			text.Replace ("F", "kaa");
			text.Replace ("G", "defrw");
			text.Replace ("H", "0vsh");
			text.Replace ("I", "jerf");
			text.Replace ("J", "qerds");
			text.Replace ("K", "5arf7");
			text.Replace ("L", "9rt5");
			text.Replace ("M", "lopol");
			text.Replace ("N", "0-a7<");
			text.Replace ("O", "1#7&9");
			text.Replace ("P", "de$");
			text.Replace ("Q", "co!a");
			text.Replace ("R", "0jol");
			text.Replace ("S", "ve4%");
			text.Replace ("T", "f~09");
			text.Replace ("U", "#ted");
			text.Replace ("V", "up;)");
			text.Replace ("W", "x$er");
			text.Replace ("X", "zet");
			text.Replace ("Y", "obj&");
			text.Replace ("Z", "loc98");
			text.Replace ("0", "vcfg");
			text.Replace ("1", "jdu");
			text.Replace ("2", "*7s&");
			text.Replace ("3", "&te5");
			text.Replace ("4", "$fef");
			text.Replace ("5", "p)7j");
			text.Replace ("6", "lo*ja");
			text.Replace ("7", "o*");
			text.Replace ("8", "3#2@");
			text.Replace ("9", "\0a");
			return text;
		}
		
		public static string Decrypt(string text)
		{
			text.Replace ("tor^y", "a");
			text.Replace ("k6a", "b");
			text.Replace ("taf9i", "c");
			text.Replace ("po", "d");
			text.Replace ("t67b", "e");
			text.Replace ("-lod;", "f");
			text.Replace ("2wr5", "g");
			text.Replace ("7ghf", "h");
			text.Replace ("4r", "i");
			text.Replace ("mopc", "j");
			text.Replace ("76ds", "k");
			text.Replace ("vedf@", "l");
			text.Replace ("gf&tf", "m");
			text.Replace ("te-d", "n");
			text.Replace ("te5g", "o");
			text.Replace ("jk", "p");
			text.Replace ("3wcb", "q");
			text.Replace ("kard", "r");
			text.Replace ("8gt", "s");
			text.Replace ("pokj", "t");
			text.Replace ("2fer", "u");
			text.Replace ("zec", "v");
			text.Replace ("artuo", "w");
			text.Replace ("gitg", "x");
			text.Replace ("ret5", "y");
			text.Replace ("peji", "z");
			text.Replace ("rgds", "A");
			text.Replace ("klhs", "B");
			text.Replace ("trgd", "C");
			text.Replace ("375d", "D");
			text.Replace ("hggs", "E");
			text.Replace ("kaa", "F");
			text.Replace ("defrw", "G");
			text.Replace ("0vsh", "H");
			text.Replace ("jerf", "I");
			text.Replace ("qerds", "J");
			text.Replace ("5arf7", "K");
			text.Replace ("9rt5", "L");
			text.Replace ("lopol", "M");
			text.Replace ("0-a7<", "N");
			text.Replace ("1#7&9", "O");
			text.Replace ("de$", "P");
			text.Replace ("co!a", "Q");
			text.Replace ("0jol", "R");
			text.Replace ("ve4%", "S");
			text.Replace ("f~09", "T");
			text.Replace ("#ted", "U");
			text.Replace ("up;)", "V");
			text.Replace ("x$er", "W");
			text.Replace ("zet", "X");
			text.Replace ("obj&", "Y");
			text.Replace ("loc98", "Z");
			text.Replace ("vcfg", "0");
			text.Replace ("jdu", "1");
			text.Replace ("*7s&", "2");
			text.Replace ("&te5", "3");
			text.Replace ("$fef", "4");
			text.Replace ("p)7j", "5");
			text.Replace ("lo*ja", "6");
			text.Replace ("o*", "7");
			text.Replace ("3#2@", "8");
			text.Replace ("\0a", "9");
			return text;
		}
	}
}

Any help appreciated. :)
Advertising
Image
Image
Image
Image
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Help debugging?

Post by m0skit0 »

Did you debug it? This is way faster than waiting for us... gdb, or any debugger.

Your code looks fine for me, even if it's awfully written (such repetitive text.Replace() calls are screaming "use a loop"). Try to post minimal compilable code that reproduces your problem.
Advertising
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
Nickolas
Posts: 174
Joined: Sat Jan 22, 2011 3:14 pm
Location: In a black hole...

Re: Help debugging?

Post by Nickolas »

m0skit0 wrote:Did you debug it? This is way faster than waiting for us... gdb, or any debugger.

Your code looks fine for me, even if it's awfully written (such repetitive text.Replace() calls are screaming "use a loop"). Try to post minimal compilable code that reproduces your problem.
Using text.Replace("a", "b"); reproduces the problem. Maybe it is something with C#? If I change the value of a variable that is a parameter of a method, inside that method and then return it, will it actually return the modified one or the original one? BTW, debugging isn't possible, as this is a .DLL that is used inside of Unity3D. So no debugging with software. :(

P.S. I know it is awfully written, in the original one I used a loop and then got rid of it to make sure it wasn't the loop causing problems.
Image
Image
Image
Image
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Help debugging?

Post by m0skit0 »

Oh, this is C#... I'm stupid, didn't notice... :roll:

You can debug compiled .NET DLL's using ILSpy Debugger for example.

And answering your question, IIRC, yes, the text object is modified. This is due to the fact that in C# (and also in Java, for example) all objects are passed as reference to methods. Thus modifying the object parameter inside a method will effectively change the original object. But the reference itself is passed by value, which means you can't reassign the object. Something like:

Code: Select all

text = new string();
inside your method will leave text object unmodified after the method ends.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
Locked

Return to “Programming”