-4

I have some algorithm written in c#:

int num3 = 260005;
string text = this.textBox1.Text;
int length = text.Length - 4;
int num5 = ((Convert.ToInt32(text.Substring(4, length)) - 0x7d1) / 2) - 0x7d1;


if (num3 == num5)
{
  do somthing!!!
}

Can somebody explain how to get correct input for textBox1? I try some math but i stuck.

I see now. I was confused with 4 character that are trow away.

  • 2
    Did you try debugging your code? At what line exactly you get stuck? Does the compilation/running give you any specific error? – Luca B. Aug 21 '14 at 08:21
  • *I have some algorithm written in c#* What algorithm? It is hard to tell what you're trying to achieve, Can you explain in some words? – Sriram Sakthivel Aug 21 '14 at 08:21
  • 3
    can you explain what the correct input *is* for `textbox1`? – Sayse Aug 21 '14 at 08:21
  • 3
    This seems like an interview question :) – Ondrej Svejdar Aug 21 '14 at 08:22
  • Well i need to get correct input. num3 i getting from reg key. Now i want to make input to text box. That input will be processed by: int length = text.Length - 4; int num5 = ((Convert.ToInt32(text.Substring(4, length)) - 0x7d1) / 2) - 0x7d1; after processing i need to get same number as a num3 (26005) – Bojan Petkovic Aug 21 '14 at 08:25
  • textBox1.Text **is** the right way to get textbox content provided your input is actually a textBox and it's called textBox1 – Luca B. Aug 21 '14 at 08:27
  • 1
    So basically you want to solve `((x - 2001) / 2) - 2001 = 260005` for `x`? – Corak Aug 21 '14 at 08:28
  • @Bojan Petkovic you're getting the input in a correct way. Are you sure that your num5 expression is correct? What do you want to do when you're getting num5? – h8red Aug 21 '14 at 08:28
  • I try to debug but didn't help so i post question here. No this is not interview question :) this is some algo that i whant to understood. – Bojan Petkovic Aug 21 '14 at 08:29
  • @Corak YES but i sole this and don't getting correct value! This is all code i will post in question answer – Bojan Petkovic Aug 21 '14 at 08:33
  • @Bojan Petkovic Also, you can just check if Convert.ToInt32(text.Substring(4, length)) == 526013 providing text.Substring(4, length) actually contains the number you need to check. – h8red Aug 21 '14 at 08:34
  • @BojanPetkovic - What number did you come up with and what input (you thought was correct) did you try and found to be incorrect? – Corak Aug 21 '14 at 08:35

2 Answers2

1

This code will match what you are looking for... This is because you are throwing away the leading FOUR characters of the text box and then doing a simple equation of ((x - 2001) / 2) - 2001 = 260005 therefore x = 526013:

int num3 = 260005;
string text = "XXXX526013";
int length = text.Length - 4;
int num5 = ((Convert.ToInt32(text.Substring(4, length)) - 0x7d1) / 2) - 0x7d1;
if (num3 == num5)
{
    Console.WriteLine("Match!");
}
else
{
    Console.WriteLine("No Match! {0}", num5);
}
Belogix
  • 8,129
  • 1
  • 27
  • 32
  • @BojanPetkovic You're welcome... You marked as the answer and then said not the answer? Question was `explain how to get correct input for textBox1` and this is the exact answer, i.e. `XXXX526013` into your text box... Bit confused? :-S – Belogix Aug 21 '14 at 08:40
0

You can simply reverse your algorithm:

string text = "asdf" + (((num3 + 0x7d1)*2) + 0x7d1);
MarkO
  • 2,143
  • 12
  • 14