# I can't understand this algorithm

I'm trying to solve this challenge but I can't understand the algorithm.

it takes the name and generate the serial with this algoritm

``````private int Encrypt(string Input)
{
int num = 0;
checked
{
int num2 = Input.Length - 1;
int num3 = num;
int num6;
for (;;)
{
int num4 = num3;
int num5 = num2;
if (num4 > num5)
{
break;
}
char @string = Conversions.ToChar(Input.Substring(num3));
num6 = (int)Math.Round(unchecked(Conversions.ToDouble(Conversion.Oct(Strings.Asc(Conversions.ToString(num6))) + Conversion.Oct(Strings.Asc(@string))) + 666.0));
num3++;
}
return num6;
}
}
``````

for example, I entered 'A' and calculated serial as shown: num6 = octal + octal + decimal

‘A’ = 65 = 101 in octal

666 = 1232 in octal

num6 = 0

num6: Octal = 0 + 101 + 1232 = 1333

Decimal = 731

but the output is : 60767

How?

• it appears you get garbage because num6 isn't initialized and also since len("A") ==1 you rbreak kicks in and returns num6 which is garbage – blabb Mar 21 '20 at 9:31

You have missed a couple of things.

• num6 isn't used directly - it's first converted to a string and then the ascii code is used
• the first addition isn't an addition - it's a string concatenation.

In cases like this where there are so many conversions going on, you really need to break it down and take it step at a time.

e.g.

``````First Part

Conversion.Oct(Strings.Asc(Conversions.ToString(num6)))
= Conversion.Oct(Strings.Asc(Conversions.ToString(0)))
= Conversion.Oct(Strings.Asc("0"))
= Conversion.Oct(48)
= "60"

Second Part

Conversion.Oct(Strings.Asc(@string))
= Conversion.Oct(Strings.Asc('A'))
= Conversion.Oct(65)
= "101"

Putting it together

Conversions.ToDouble("60"+ "101") + 666
= Conversions.ToDouble( "60101") + 666
= 60101 + 666
= 60767
``````

Alternatively, just paste the code into a simple C#/VB console application and run it to see what happens.