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. Other Discussions
  3. The Weird and The Wonderful
  4. \r\n

\r\n

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
30 Posts 15 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.
  • J Offline
    J Offline
    jofli
    wrote on last edited by
    #1

    Reflector showed me this 'gem' in a contractors project:

    string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

    this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

    kind regards, JoFli

    T I D P D 6 Replies Last reply
    0
    • J jofli

      Reflector showed me this 'gem' in a contractors project:

      string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

      this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

      kind regards, JoFli

      T Offline
      T Offline
      Thomas Weller 0
      wrote on last edited by
      #2

      I bet, the creator of this is proud of his clever and 'creative' solution... :sigh:

      blog.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
      Programmer - an organism that turns coffee into software.

      1 Reply Last reply
      0
      • J jofli

        Reflector showed me this 'gem' in a contractors project:

        string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

        this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

        kind regards, JoFli

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        Careful, that might break internationally. I've had issues with one of my users, where his region settings would screw up and the computer would interpret a leading "1" as a "+" (So "13" would be "+3")... So he SHOULD have added in the proper NumberFormatInfo for invariant culture settings! (Yes, this is a joke... Sorry, It's the best I can do at 10am)

        Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

        1 Reply Last reply
        0
        • J jofli

          Reflector showed me this 'gem' in a contractors project:

          string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

          this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

          kind regards, JoFli

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Is this called obfuscation?

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          I 1 Reply Last reply
          0
          • J jofli

            Reflector showed me this 'gem' in a contractors project:

            string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

            this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

            kind regards, JoFli

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            A BASIC developer new to C#?

            jofli wrote:

            Recieved

            And maybe didn't graduate high school either? :-D

            L J 2 Replies Last reply
            0
            • D dan sh

              Is this called obfuscation?

              50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #6

              If that's obfuscation, I'm not impressed... If I wanted to make it REALLY confusing, I'd do something like this:

              const string blarphnik = "51209576120381929170992";
              string elkabong = Convert.ToChar(int.Parse(blarphnik.SubString(1,2))

              • int.Parse(blarphnik /* If I had a pet monkey, I'd name it blarphnik */.SubString(8 /* What a nice number */,1)))
              • Convert.ToChar(int.Parse(blarphnik.SubString(18, 2))
                / int.Parse(blarphnik.SubString(6,1) /* Todo: Fix this */));

              And then I would publish this as part of a self-help book entitled "How to Drive a Programmer Insane"

              Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

              P D OriginalGriffO P 4 Replies Last reply
              0
              • I Ian Shlasko

                If that's obfuscation, I'm not impressed... If I wanted to make it REALLY confusing, I'd do something like this:

                const string blarphnik = "51209576120381929170992";
                string elkabong = Convert.ToChar(int.Parse(blarphnik.SubString(1,2))

                • int.Parse(blarphnik /* If I had a pet monkey, I'd name it blarphnik */.SubString(8 /* What a nice number */,1)))
                • Convert.ToChar(int.Parse(blarphnik.SubString(18, 2))
                  / int.Parse(blarphnik.SubString(6,1) /* Todo: Fix this */));

                And then I would publish this as part of a self-help book entitled "How to Drive a Programmer Insane"

                Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Make the constant string a resource and put the constant ints in the config. :-D

                I 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Make the constant string a resource and put the constant ints in the config. :-D

                  I Offline
                  I Offline
                  Ian Shlasko
                  wrote on last edited by
                  #8

                  No no no... It's harder to hide it that way. With code like this, you want it buried deeply inside a commonly-used DLL in a not-quite-obsolete language, so when you get laid off and the next guy in line decides to rewrite the code and modernize it, they have a heart attack when they see it. At least, That was probably what some of my predecessors were thinking...

                  Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                  P 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    A BASIC developer new to C#?

                    jofli wrote:

                    Recieved

                    And maybe didn't graduate high school either? :-D

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    PIEBALDconsult wrote:

                    A BASIC developer new to C#?

                    No way. Any Basic developer would use either Chr$(13) & Chr$(10) or vbCrLf, both much more readable than the OP. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    1 Reply Last reply
                    0
                    • J jofli

                      Reflector showed me this 'gem' in a contractors project:

                      string cBRK = Convert.ToChar(int.Parse("13")).ToString() + Convert.ToChar(int.Parse("10")).ToString();

                      this.ReportStatus("93101Bytes" + cBRK + BytesRecieved.ToString() + cBRK + fileSize.ToString() + cBRK);

                      kind regards, JoFli

                      D Offline
                      D Offline
                      David Skelly
                      wrote on last edited by
                      #10

                      My guess is that this is an artifact of Reflector, not of the original coder. I do know that in VB, the Chr() function actually does use Convert.ToChar internally so my guess is that C# does the same. Who knows what Environment.NewLine does internally. I assume that the compiler has in-lined the Chr function, and Reflector has simply given you back what the compiler produced. Anyone with too much free time on their hands and a handy copy of Reflector is invited to experiment to find out what the compiler does with this sort of thing. Reflector is showing you what the code looks like after the compiler has munged it around and played merry havoc with your beautiful code.

                      D C G 3 Replies Last reply
                      0
                      • D David Skelly

                        My guess is that this is an artifact of Reflector, not of the original coder. I do know that in VB, the Chr() function actually does use Convert.ToChar internally so my guess is that C# does the same. Who knows what Environment.NewLine does internally. I assume that the compiler has in-lined the Chr function, and Reflector has simply given you back what the compiler produced. Anyone with too much free time on their hands and a handy copy of Reflector is invited to experiment to find out what the compiler does with this sort of thing. Reflector is showing you what the code looks like after the compiler has munged it around and played merry havoc with your beautiful code.

                        D Offline
                        D Offline
                        David Skelly
                        wrote on last edited by
                        #11

                        OK, there is no Chr function in C# but you know what I mean.

                        L 1 Reply Last reply
                        0
                        • I Ian Shlasko

                          If that's obfuscation, I'm not impressed... If I wanted to make it REALLY confusing, I'd do something like this:

                          const string blarphnik = "51209576120381929170992";
                          string elkabong = Convert.ToChar(int.Parse(blarphnik.SubString(1,2))

                          • int.Parse(blarphnik /* If I had a pet monkey, I'd name it blarphnik */.SubString(8 /* What a nice number */,1)))
                          • Convert.ToChar(int.Parse(blarphnik.SubString(18, 2))
                            / int.Parse(blarphnik.SubString(6,1) /* Todo: Fix this */));

                          And then I would publish this as part of a self-help book entitled "How to Drive a Programmer Insane"

                          Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                          D Offline
                          D Offline
                          dan sh
                          wrote on last edited by
                          #12

                          I should have placed the joke icon. :doh:

                          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

                          1 Reply Last reply
                          0
                          • I Ian Shlasko

                            If that's obfuscation, I'm not impressed... If I wanted to make it REALLY confusing, I'd do something like this:

                            const string blarphnik = "51209576120381929170992";
                            string elkabong = Convert.ToChar(int.Parse(blarphnik.SubString(1,2))

                            • int.Parse(blarphnik /* If I had a pet monkey, I'd name it blarphnik */.SubString(8 /* What a nice number */,1)))
                            • Convert.ToChar(int.Parse(blarphnik.SubString(18, 2))
                              / int.Parse(blarphnik.SubString(6,1) /* Todo: Fix this */));

                            And then I would publish this as part of a self-help book entitled "How to Drive a Programmer Insane"

                            Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

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

                            Tcha! The youth and inexperience shows! Every real programmer knows that the best compression method is to use a random number generator with the correct seed to regenerate the uncompressed file - then all you need to do is send the seed. Extending this:

                                    Random rs;
                                    const string blarphnik = "51209576120381929170992";
                                    int dontTouchThis = int.Parse(blarphnik.Substring(12,1));
                                    rs = new Random(dontTouchThis);
                                    StringBuilder sb = new StringBuilder(2);
                                    sb.Append(Convert.ToChar(rs.Next(15)));
                                    int dontTouchThisEither = int.Parse(blarphnik.Substring(10,1));
                                    rs = new Random(dontTouchThisEither);
                                    sb.Append(Convert.ToChar(rs.Next(15)));
                                    string cBRK = sb.ToString();
                            

                            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

                            "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

                            I 1 Reply Last reply
                            0
                            • OriginalGriffO OriginalGriff

                              Tcha! The youth and inexperience shows! Every real programmer knows that the best compression method is to use a random number generator with the correct seed to regenerate the uncompressed file - then all you need to do is send the seed. Extending this:

                                      Random rs;
                                      const string blarphnik = "51209576120381929170992";
                                      int dontTouchThis = int.Parse(blarphnik.Substring(12,1));
                                      rs = new Random(dontTouchThis);
                                      StringBuilder sb = new StringBuilder(2);
                                      sb.Append(Convert.ToChar(rs.Next(15)));
                                      int dontTouchThisEither = int.Parse(blarphnik.Substring(10,1));
                                      rs = new Random(dontTouchThisEither);
                                      sb.Append(Convert.ToChar(rs.Next(15)));
                                      string cBRK = sb.ToString();
                              

                              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

                              I Offline
                              I Offline
                              Ian Shlasko
                              wrote on last edited by
                              #14

                              Oh right, I totally forgot about that... But you have to comment your code to make sure it's legible!

                              Random rs;
                              const string blarphnik = "51209576120381929170992";
                              int dontTouchThis = int.Parse(blarphnik.Substring(12,1));
                              rs = new Random(dontTouchThis /* That's what SHE said! */);
                              StringBuilder sb = new StringBuilder(2);
                              sb.Append(Convert.ToChar(rs.Next(15)));
                              int dontTouchThisEither = int.Parse(blarphnik.Substring(10,1));
                              rs = new Random(dontTouchThisEither /* That's what her SISTER said */);
                              sb.Append(Convert.ToChar(rs.Next(15)));
                              string cBRK = sb.ToString();

                              Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                              1 Reply Last reply
                              0
                              • D David Skelly

                                OK, there is no Chr function in C# but you know what I mean.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                The correct code in C# is "\r\n" which is ldstr "\r\n" in MSIL (which is generated exactly like that by the C# compiler)

                                D 1 Reply Last reply
                                0
                                • L Lost User

                                  The correct code in C# is "\r\n" which is ldstr "\r\n" in MSIL (which is generated exactly like that by the C# compiler)

                                  D Offline
                                  D Offline
                                  David Skelly
                                  wrote on last edited by
                                  #16

                                  The OP doesn't say that the code was written in C#, it was reverse engineered using Reflector. Reflector is capable of taking code written in VB and decompiling it back into C#. The resulting C# code may look pretty odd, but you will at least be able to see what it is doing.

                                  J 1 Reply Last reply
                                  0
                                  • D David Skelly

                                    The OP doesn't say that the code was written in C#, it was reverse engineered using Reflector. Reflector is capable of taking code written in VB and decompiling it back into C#. The resulting C# code may look pretty odd, but you will at least be able to see what it is doing.

                                    J Offline
                                    J Offline
                                    jofli
                                    wrote on last edited by
                                    #17

                                    That's right, but afaik he only codes c#.

                                    D 1 Reply Last reply
                                    0
                                    • J jofli

                                      That's right, but afaik he only codes c#.

                                      D Offline
                                      D Offline
                                      David Skelly
                                      wrote on last edited by
                                      #18

                                      Well, OK, maybe he's just an idiot. As far as I am aware, Reflector doesn't stop people from writing bad code and will happily decompile bad C# back into bad C#. GIGO, as they say. For what it's worth, the MS .NET Framework implementation of C# Environment.NewLine returns a literal constant "\r\n". No idea what Mono does. So if the contractor wrote this in C#, goodness only knows what was going through his brain. Nothing, probably, if he's like some of the contractors I've known.

                                      1 Reply Last reply
                                      0
                                      • P PIEBALDconsult

                                        A BASIC developer new to C#?

                                        jofli wrote:

                                        Recieved

                                        And maybe didn't graduate high school either? :-D

                                        J Offline
                                        J Offline
                                        jofli
                                        wrote on last edited by
                                        #19

                                        PIEBALDconsult wrote:

                                        jofli wrote: Recieved And maybe didn't graduate high school either? Big Grin

                                        http://www.recieved.co.uk/[^] Well, at least he tried to use English namings. And I must admit that sometimes it's not that easy, if you're not a native speaker.

                                        1 Reply Last reply
                                        0
                                        • I Ian Shlasko

                                          No no no... It's harder to hide it that way. With code like this, you want it buried deeply inside a commonly-used DLL in a not-quite-obsolete language, so when you get laid off and the next guy in line decides to rewrite the code and modernize it, they have a heart attack when they see it. At least, That was probably what some of my predecessors were thinking...

                                          Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #20

                                          Ian Shlasko wrote:

                                          It's harder to hide it that way.

                                          No, it hides it in different places; your way has all the information in one place. Plus, using a resource and config makes it brittle -- if someone changes or removes the entries chaos will ensue.

                                          I 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