Click here to Skip to main content
15,896,727 members
Home / Discussions / C#
   

C#

 
QuestionBook Help Pin
NaveenHS15-Sep-10 20:55
NaveenHS15-Sep-10 20:55 
AnswerRe: Book Help Pin
Swiftain15-Sep-10 20:58
Swiftain15-Sep-10 20:58 
GeneralRe: Book Help Pin
NaveenHS15-Sep-10 21:09
NaveenHS15-Sep-10 21:09 
GeneralRe: Book Help Pin
N a v a n e e t h15-Sep-10 22:56
N a v a n e e t h15-Sep-10 22:56 
GeneralRe: Book Help Pin
NaveenHS15-Sep-10 23:17
NaveenHS15-Sep-10 23:17 
AnswerRe: Book Help Pin
i.j.russell16-Sep-10 1:14
i.j.russell16-Sep-10 1:14 
AnswerRe: Book Help [modified] Pin
Luc Pattyn16-Sep-10 1:21
sitebuilderLuc Pattyn16-Sep-10 1:21 
QuestionBack with base10, an example code. Hopefully I can exaplain now Pin
stephen.darling15-Sep-10 10:43
stephen.darling15-Sep-10 10:43 
Hi again, sorry if I should not have started a new thread, but I have found the c++ code for what I wanted.

1) This is c++, I do not know how I would do it in c#

2) This function only decodes a string of digits into the byte arra, so I still dont know how to encode a byte array ito the string (reverse)

So... This function takes an installation ID (or what will be a serial number) and decodes it into its byte representation of the number.

int DecodeInstID(char *InstID, unsigned char *Result, int ResLen)
{
	int i, k, m, Groups;
	int Sum, Digit, Aux;

	if (strlen(InstID) != 58)
		fprintf(stderr, "Warning: Installation ID has non-standard length.\n");

	if (strlen(InstID) % 7 < 2)
	{
		fprintf(stderr, "Installation ID has invalid length.\n");
		return -1;
	}

	memset(Result, 0, ResLen);
	
	Groups = (strlen(InstID) + 6) / 7;

	for (i = 0; i < Groups * 7; i += 7)
	{
		Sum = 0;

		for (k = 0; k < 5 && InstID[i + k + 1] != 0; k++)
		{
			Digit = InstID[i + k] - '0';

			if (Digit < 0 || Digit > 9)
			{
				fprintf(stderr, "Invalid digit in group '");

				for (k = 0; k < 6 && InstID[i + k] != 0; k++)
					fprintf(stderr, "%c", InstID[i + k]);

				fprintf(stderr, "'.\n");
				return -1;
			}
			
			Aux = Digit;
			m = 0;

			do
			{
				Aux += Result[m] * 10;
				Result[m++] = (unsigned char)(Aux & 255);

				Aux >>= 8;
			}
			while (m < ResLen);

			if ((k & 1) != 0)
				Digit *= 2;

			Sum += Digit;
		}

		Digit = InstID[i + k++] - '0';

		if (Digit != Sum % 7)
		{
			fprintf(stderr, "Invalid check digit in group '");

			for (k = 0; k < 6 && InstID[i + k] != 0; k++)
				fprintf(stderr, "%c", InstID[i + k]);

			fprintf(stderr, "'.\n");
			return -1;
		}

		if (InstID[i + k] != '-' && InstID[i + k] != 0)
		{
			fprintf(stderr, "Expected '-' character after group '");

			for (k = 0; k < 6 && InstID[i + k] != 0; k++)
				fprintf(stderr, "%c", InstID[i + k]);

			fprintf(stderr, "'.\n");
			return -1;
		}
	}

	return 0;
}



I know its in c++, but maybe someone can at least figure out what is going on and then maybe this time understand what I want.

So, if you pass ain installation ID string into this function, like the following

("23334 324234 324234 234234 etc")

You get the byte array of the multi precision value for it.

Now, I have my original 2 qustions....

1) How would I do this in c#

2) How would I code a reverse function to ENCODE a byte array (that the above creates) back into a string, like above.

Then I would be able to encode a byte array into a readable long string of digits to give to the user, and,

then DECODE the string (like above) into a byte array

Hopefully you may now understand what I am trying to do, and I cannot start to explain how much I want to do this as I found c# code before and cannot find it now.

Thank you loads in advance, I do appreciate any help.
Steve
AnswerRe: Back with base10, an example code. Hopefully I can exaplain now Pin
Ennis Ray Lynch, Jr.15-Sep-10 10:53
Ennis Ray Lynch, Jr.15-Sep-10 10:53 
GeneralRe: Back with base10, an example code. Hopefully I can exaplain now Pin
stephen.darling15-Sep-10 11:12
stephen.darling15-Sep-10 11:12 
AnswerMessage Closed Pin
15-Sep-10 22:09
stancrm15-Sep-10 22:09 
GeneralRe: Back with base10, an example code. Hopefully I can exaplain now Pin
stephen.darling16-Sep-10 4:32
stephen.darling16-Sep-10 4:32 
AnswerRe: Back with base10, an example code. Hopefully I can exaplain now Pin
David Skelly15-Sep-10 22:41
David Skelly15-Sep-10 22:41 
GeneralRe: Back with base10, an example code. Hopefully I can exaplain now Pin
Bassam Abdul-Baki16-Sep-10 3:25
professionalBassam Abdul-Baki16-Sep-10 3:25 
GeneralRe: Back with base10, an example code. Hopefully I can exaplain now Pin
David Skelly16-Sep-10 5:58
David Skelly16-Sep-10 5:58 
QuestionTCPIP client server communications Pin
dwolver15-Sep-10 3:03
dwolver15-Sep-10 3:03 
AnswerMessage Closed Pin
15-Sep-10 3:33
stancrm15-Sep-10 3:33 
GeneralRe: TCPIP client server communications Pin
dwolver15-Sep-10 4:34
dwolver15-Sep-10 4:34 
QuestionI'm trying to get a Session and redirect in Globa.asax Pin
luiz sync15-Sep-10 2:13
luiz sync15-Sep-10 2:13 
AnswerRe: I'm trying to get a Session and redirect in Globa.asax Pin
Calla15-Sep-10 2:42
Calla15-Sep-10 2:42 
Questionsetup and unistall Pin
tomorrow_ft15-Sep-10 2:03
tomorrow_ft15-Sep-10 2:03 
AnswerRe: setup and unistall Pin
Calla15-Sep-10 2:36
Calla15-Sep-10 2:36 
GeneralRe: setup and unistall Pin
tomorrow_ft15-Sep-10 2:48
tomorrow_ft15-Sep-10 2:48 
GeneralRe: setup and unistall Pin
tomorrow_ft15-Sep-10 3:03
tomorrow_ft15-Sep-10 3:03 
GeneralRe: setup and unistall Pin
Calla15-Sep-10 22:47
Calla15-Sep-10 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.