Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Hex to UUEncode in C#

Hex to UUEncode in C#

Scheduled Pinned Locked Moved C#
csharphelp
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NJdotnetdev
    wrote on last edited by
    #1

    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.

    OriginalGriffO 1 Reply Last reply
    0
    • N NJdotnetdev

      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.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      N 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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...

        N Offline
        N Offline
        NJdotnetdev
        wrote on last edited by
        #3

        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.

        OriginalGriffO 1 Reply Last reply
        0
        • N NJdotnetdev

          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.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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...

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          N 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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...

            N Offline
            N Offline
            NJdotnetdev
            wrote on last edited by
            #5

            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.

            OriginalGriffO 1 Reply Last reply
            0
            • N NJdotnetdev

              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.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              N 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                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...

                N Offline
                N Offline
                NJdotnetdev
                wrote on last edited by
                #7

                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.

                OriginalGriffO 1 Reply Last reply
                0
                • N NJdotnetdev

                  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.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  N 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    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...

                    N Offline
                    N Offline
                    NJdotnetdev
                    wrote on last edited by
                    #9

                    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.

                    OriginalGriffO 1 Reply Last reply
                    0
                    • N NJdotnetdev

                      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.

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #10

                      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 0xFE

                      Which 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...

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      N 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        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 0xFE

                        Which 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...

                        N Offline
                        N Offline
                        NJdotnetdev
                        wrote on last edited by
                        #11

                        Yeah.. Thanks a lot for the explanation.

                        OriginalGriffO 1 Reply Last reply
                        0
                        • N NJdotnetdev

                          Yeah.. Thanks a lot for the explanation.

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #12

                          You're welcome!

                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups