Click here to Skip to main content
15,915,774 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have asked this question but but coders didnt seem to know what i wanted as it was hard to explain. It is driving me insane so ill give it anouther shot.

OK, My application asks the user to enter a long installation ID:

50 decimal digits that are
divided into groups of six digits each, as in
002666-077894-484890-114573-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XX


then we have:

Removing the check digits results in a 41-digit decimal number. A
decimal number of this length roughly corresponds to a 136-bit binary
number. In fact, the 41-digit number is just the decimal encoding of
such a 136-bit multi-precision integer, which is stored in little
endian byte order as a byte array. Hence, the above Installation ID
can also be represented as a sequence of 17 bytes as in
0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX
0x94 0xAA 0x46 0xD6 0x0F 0xBD 0x2C 0xC8
0x00


So my question is this:

How do i get the installation id string ("xxxxxx-xxxxxx- etc") into a byte array above, that represents the decimal encoding of the number.

This is what i want to do, just so i can try and make myself very clear.

I want a fixed length byte array, like:

0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX 0xXX
0x94 0xAA 0x46 0xD6 0x0F 0xBD 0x2C 0xC8
0x00

I will then encrypt the byte array with a fixed length key.

I then want to represent the byte array as its number representation, in a string:

002666-077894-484890-114573-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XX

I realy hope this helps.
Thank you again.
Steve
Posted

Try this;

C#
string startValue = "456345-007876-343234-765676-543456-566565-321234-345654".Replace("-", "");
char[] indivualNumbers = startValue.ToCharArray();
byte[] arrayValue = new byte[indivualNumbers.Length];
int numberCounter = 0;
foreach (char numberValue in indivualNumbers)
{
   arrayValue[numberCounter] = (byte)Convert.ToInt32(numberValue);
   ++numberCounter;
}


This is the end result of the second option I gave in your previous question.
 
Share this answer
 
Two words "Binary Math".

You need to walk the string from lest significant digit to most significant.

store the current string value in a byte call this currentValue.
have another byte[] with the multiplier.
and another byte[] for the result.

start off with;
byte[] multiplier = new byte[1];
multiplier[0] = 1;
byte currentValue = null; 
byte[] result = new byte[1];
result[0] = 0;

foreach(char charValue in "5634007873432376567543455665632123345654".toCharArray().Reverse())
{
  currentValue = (byte)Convert.ToInt16(charValue ); 

  //Next two lines require binary math routines
  result = result + (currentValue * multiplier);
  multiplier = multiplier  * 10;
}


obviously this is the pseudocode version as the byte arrays, multiplier and result, will need to grow as the number stored in them gets larger.
 
Share this answer
 
Thanks again but this is not what i want.

Your answer produces 48 bytes and as i am trying to explain above, the decimal representation of that string is supposed to be 17 bytes long.

I am basicaly trying to reproduce the following in c#


http://www.licenturion.com/xp/fully-licensed-wpa.txt

Hope that helps as i have now drew a blank, and i wouldnt care but i found the answer before and cant get it again.

Thank you
Steve
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900