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. left Circular shift ??

left Circular shift ??

Scheduled Pinned Locked Moved C#
helpquestion
21 Posts 9 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.
  • H Henry Minute

    If you have to do a circular shift on a number why are you faffing about with strings? There are plenty of examples on the web to do this. Here[^], for example. There are loads of others though, simply search on c# circularleftshift.

    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

    Z Offline
    Z Offline
    ZeroOne8
    wrote on last edited by
    #9

    Henry Minute wrote:

    If you have to do a circular shift on a number why are you faffing about with strings?

    because h1 and h2 is result from function that return string . i will see if i can use another function , or convert the return data type . thx henry .

    H 1 Reply Last reply
    0
    • Z ZeroOne8

      Henry Minute wrote:

      If you have to do a circular shift on a number why are you faffing about with strings?

      because h1 and h2 is result from function that return string . i will see if i can use another function , or convert the return data type . thx henry .

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #10

      Try here[^].

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • P Pete OHanlon

        Have you looked at this[^] article?

        I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        Z Offline
        Z Offline
        ZeroOne8
        wrote on last edited by
        #11

        yes i see that article , the Shift function dose not work with me , the encryption in the article is encrypt binary files , but i need to encrypt some text.

        OriginalGriffO 1 Reply Last reply
        0
        • Z ZeroOne8

          thank you much Pete :) in fact my real problem is : I'm trying to implement Simplified DES (DES is an encryption algorithm ) on of the step to implement is Left Circular shift for every halve of the key if the key is 1000001100 string h1 = 10000 string h2 = 01100 then do Left Circular shift by 1 , so 10000 will be 00001 and 01100 will be 11000 i need function to do that shift :) I tried a lot, but there is no result :mad:.

          modified on Sunday, November 14, 2010 1:34 PM

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

          If you want it to be as slow as possible, then by all means do math with strings.

          1 Reply Last reply
          0
          • Z ZeroOne8

            hello every one :) any body can help me to find function that can do left Circular shift for any string for Ex: string is codeproject i need it to be odeprojectc pls help me :)

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #13

            Here's a hint:

            str.Substring(shiftAmount) + str.Substring(0, shiftAmount);

            Do you really think it would be that hard to implement this yourself?

            [Forum Guidelines]

            Z P 2 Replies Last reply
            0
            • A AspDotNetDev

              Here's a hint:

              str.Substring(shiftAmount) + str.Substring(0, shiftAmount);

              Do you really think it would be that hard to implement this yourself?

              [Forum Guidelines]

              Z Offline
              Z Offline
              ZeroOne8
              wrote on last edited by
              #14

              it is very good idea it has never crossed my mind ,it so easy and so small i do this

                  public static String CircularShift(string Subject, int Count)
                  {
                      int l = Subject.Length;
                      char\[\] text = new char\[l\];
                      for (int i = 0; i < l; i++)
                      {
                          text\[i\] = Subject\[(i + Count) % l\];
              
                      }
              
                      String output = "";
                      for (int i = 0; i < l; i++)
                      {
                          output += text\[i\];
                      }
              
                      return output;
                  }
              

              but i will use your idea . thank you very much. an thx for every one who trying to help .

              modified on Sunday, November 14, 2010 1:36 PM

              L 1 Reply Last reply
              0
              • Z ZeroOne8

                it is very good idea it has never crossed my mind ,it so easy and so small i do this

                    public static String CircularShift(string Subject, int Count)
                    {
                        int l = Subject.Length;
                        char\[\] text = new char\[l\];
                        for (int i = 0; i < l; i++)
                        {
                            text\[i\] = Subject\[(i + Count) % l\];
                
                        }
                
                        String output = "";
                        for (int i = 0; i < l; i++)
                        {
                            output += text\[i\];
                        }
                
                        return output;
                    }
                

                but i will use your idea . thank you very much. an thx for every one who trying to help .

                modified on Sunday, November 14, 2010 1:36 PM

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

                please stop using confusing single-character identifiers such as this one: l which could be a letter or a digit depending on the font that is used to display it. BTW: Most letters (such as i and n) are OK, however "L".ToLower() sure is not. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                Z 1 Reply Last reply
                0
                • L Luc Pattyn

                  please stop using confusing single-character identifiers such as this one: l which could be a letter or a digit depending on the font that is used to display it. BTW: Most letters (such as i and n) are OK, however "L".ToLower() sure is not. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  Z Offline
                  Z Offline
                  ZeroOne8
                  wrote on last edited by
                  #16

                  You're right , really i can't found different between l and 1 in VS2008 it is the same Usually i used letter such as i j x y any way thx for your advice ;)

                  1 Reply Last reply
                  0
                  • Z ZeroOne8

                    yes i see that article , the Shift function dose not work with me , the encryption in the article is encrypt binary files , but i need to encrypt some text.

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

                    mnabrisi wrote:

                    the encryption in the article is encrypt binary files , but i need to encrypt some text.

                    What do you think text is? Text is a subset of binary. Anything that works for binary, will work for text...

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    "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

                    Z 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      mnabrisi wrote:

                      the encryption in the article is encrypt binary files , but i need to encrypt some text.

                      What do you think text is? Text is a subset of binary. Anything that works for binary, will work for text...

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                      Z Offline
                      Z Offline
                      ZeroOne8
                      wrote on last edited by
                      #18

                      i know that . -- but if you see my code you will know what i meaning .

                      1 Reply Last reply
                      0
                      • A AspDotNetDev

                        Here's a hint:

                        str.Substring(shiftAmount) + str.Substring(0, shiftAmount);

                        Do you really think it would be that hard to implement this yourself?

                        [Forum Guidelines]

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

                        That'll blow up if the shiftAmount is out of range. Plus I prefer to allow negative values to specify a shift in the other direction...

                        shiftAmount %= str.Length ;

                        if ( shiftAmount < 0 ) shiftAmount += str.Length ;

                        A 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          That'll blow up if the shiftAmount is out of range. Plus I prefer to allow negative values to specify a shift in the other direction...

                          shiftAmount %= str.Length ;

                          if ( shiftAmount < 0 ) shiftAmount += str.Length ;

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #20

                          That is why it was a hint and not a solution. I generally avoid giving full solutions when the solution is so easy that the OP should be able to figure it out.

                          [Forum Guidelines]

                          P 1 Reply Last reply
                          0
                          • A AspDotNetDev

                            That is why it was a hint and not a solution. I generally avoid giving full solutions when the solution is so easy that the OP should be able to figure it out.

                            [Forum Guidelines]

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

                            Yar, me too.

                            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