Hex to UUEncode in C#
-
Following is the working code which decodes UUEncoded information to the correct hex value: Code: string input = "MTA0ODU3NjAA="; byte[] decoded = Convert.FromBase64String(input.TrimEnd(new char[] { '=' })); String value = ASCIIEncoding.ASCII.GetString(decoded); int output = Convert.ToInt32(value); string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16); Output: temp = "0000A0"; I am looking for help to reverse this process. Input: "0000A0" and get output as: "MTA0ODU3NjAA", since '=' are used for padding only.
-
Following is the working code which decodes UUEncoded information to the correct hex value: Code: string input = "MTA0ODU3NjAA="; byte[] decoded = Convert.FromBase64String(input.TrimEnd(new char[] { '=' })); String value = ASCIIEncoding.ASCII.GetString(decoded); int output = Convert.ToInt32(value); string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16); Output: temp = "0000A0"; I am looking for help to reverse this process. Input: "0000A0" and get output as: "MTA0ODU3NjAA", since '=' are used for padding only.
And? What help do you need? What have you tried? Where are you stuck?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
And? What help do you need? What have you tried? Where are you stuck?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
I wrote the initial logic of converting the UUEncoded data to hex value. This hex value is being used in C# code. Now I want to save it back as UUEncoded data. I am not sure how to reverse engineer it. Need some advise.
-
I wrote the initial logic of converting the UUEncoded data to hex value. This hex value is being used in C# code. Now I want to save it back as UUEncoded data. I am not sure how to reverse engineer it. Need some advise.
You wrote this:
string input = "MTA0ODU3NjAA=";
byte[] decoded = Convert.FromBase64String(input.TrimEnd(new char[] { '=' }));
String value = ASCIIEncoding.ASCII.GetString(decoded);
int output = Convert.ToInt32(value);
string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16);And you can't reverse it? Um. What part of the two relevant lines can't you understand?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
You wrote this:
string input = "MTA0ODU3NjAA=";
byte[] decoded = Convert.FromBase64String(input.TrimEnd(new char[] { '=' }));
String value = ASCIIEncoding.ASCII.GetString(decoded);
int output = Convert.ToInt32(value);
string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16);And you can't reverse it? Um. What part of the two relevant lines can't you understand?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
This is the one I am not able to reverse: string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16); Not good with these conversions.
-
This is the one I am not able to reverse: string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16); Not good with these conversions.
What conversions? All it does is extract the lowest three bytes and output them in little endian order a hex strings. Now come on - be honest. You didn't write that, did you?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
What conversions? All it does is extract the lowest three bytes and output them in little endian order a hex strings. Now come on - be honest. You didn't write that, did you?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
I did... You can search google, for the code and there will not be a single hit for similar code. This was even posted by me on the same forum, couple of days back as the answer. PLEASE DON'T help if you are trying not to and prove that we are lying for what we are saying.
-
I did... You can search google, for the code and there will not be a single hit for similar code. This was even posted by me on the same forum, couple of days back as the answer. PLEASE DON'T help if you are trying not to and prove that we are lying for what we are saying.
I'm not trying to prove anything! :laugh: All I'm sayign is: how come you wrote that code and don't understand what it does?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
I'm not trying to prove anything! :laugh: All I'm sayign is: how come you wrote that code and don't understand what it does?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
Okay... Sorry I got it in a bad way. I did get the steps from a peer who had an idea. From that I read tons of articles and wrote step by step code. But, I didn't want to go through that process again, so was looking for a one line solution or may be optimize my approach for the already written code. I can write C# but these conversions from hex to UUEncode and vice versa is not my cup of tea.
-
Okay... Sorry I got it in a bad way. I did get the steps from a peer who had an idea. From that I read tons of articles and wrote step by step code. But, I didn't want to go through that process again, so was looking for a one line solution or may be optimize my approach for the already written code. I can write C# but these conversions from hex to UUEncode and vice versa is not my cup of tea.
OK. Look at the line you worte:
string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16);
Let's reformat that so it's more obvious whats happening:
string temp = String.Format("{0:X02}{1:X02}{2:X02}",
(output & 0xFF0000FF) >> 0,
(output & 0xFF00FF00) >> 8,
(output & 0xFFFF0000) >> 16);The String.Format bit is trivial: output each of three values as two hex digits with leadign zeros if necessary. The other three do the same thing, just they work on three different bytes of the input number. (Except if you pass though a negative number, it's all going to fail badly - that's the "FF" ate th left hand side adding in the top byte to all three vlaues) The top one extracts the least significant byte: x & 0x00000FF The middle one extracts the middle byte value x & 0x00FF00, then shifts if down eight bit places to move it to the least significant position. The top one does teh same with the top value of teh three, moving it 16 bits down. So if the
output
variable held 0x00FEDCBA:The first part extracts 0xBA
The second extracts 0xDC
The third extracts 0xFEWhich is then converted to a string "BADCFE" - little endian format because the least significant byte is first. So to reverse it, break the string into three parts with SubString, convert each part with int.Parse(part, NumberStyles.HexNumber) and use << to shift it back where it came from. Simple enough?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
OK. Look at the line you worte:
string temp = String.Format("{0:X02}{1:X02}{2:X02}", (output & 0xFF0000FF) >> 0, (output & 0xFF00FF00) >> 8, (output & 0xFFFF0000) >> 16);
Let's reformat that so it's more obvious whats happening:
string temp = String.Format("{0:X02}{1:X02}{2:X02}",
(output & 0xFF0000FF) >> 0,
(output & 0xFF00FF00) >> 8,
(output & 0xFFFF0000) >> 16);The String.Format bit is trivial: output each of three values as two hex digits with leadign zeros if necessary. The other three do the same thing, just they work on three different bytes of the input number. (Except if you pass though a negative number, it's all going to fail badly - that's the "FF" ate th left hand side adding in the top byte to all three vlaues) The top one extracts the least significant byte: x & 0x00000FF The middle one extracts the middle byte value x & 0x00FF00, then shifts if down eight bit places to move it to the least significant position. The top one does teh same with the top value of teh three, moving it 16 bits down. So if the
output
variable held 0x00FEDCBA:The first part extracts 0xBA
The second extracts 0xDC
The third extracts 0xFEWhich is then converted to a string "BADCFE" - little endian format because the least significant byte is first. So to reverse it, break the string into three parts with SubString, convert each part with int.Parse(part, NumberStyles.HexNumber) and use << to shift it back where it came from. Simple enough?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
Yeah.. Thanks a lot for the explanation.
-
Yeah.. Thanks a lot for the explanation.
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...