left Circular shift ??
-
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 :)
public static string
CircularShift
(
this string Subject
,
int Count
)
{
string result ;// Left as an exercise... return ( result ) ;
}
-
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 :)
mnabrisi wrote:
any body can help me to find function that can do left Circular shift for any string
Indeed I can. The first step you need to do is to break the problem down into smaller steps. Here, it seems that your logic is - for any string, take the first character off it and put it at the end. Consider your edge cases - what happens if no characters are input? What about if only one character is input? There you go - you now know what the problem is that you're trying to solve. Good luck.
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
-
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 :)
There isn't one. You have to write it yourself.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
mnabrisi wrote:
any body can help me to find function that can do left Circular shift for any string
Indeed I can. The first step you need to do is to break the problem down into smaller steps. Here, it seems that your logic is - for any string, take the first character off it and put it at the end. Consider your edge cases - what happens if no characters are input? What about if only one character is input? There you go - you now know what the problem is that you're trying to solve. Good luck.
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
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
-
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 :)
AFAIK there is no built in function to do this. It would be fairly easy to write your own, though. Assuming an 11 character string. One way would be to reverse the string and then create a new string from the last 10 characters of the original + the last character of the reversed string. There are loads more ways though.
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.”
-
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
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.”
-
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
-
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.”
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 .
-
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 .
-
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
-
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 :)
Here's a hint:
str.Substring(shiftAmount) + str.Substring(0, shiftAmount);
Do you really think it would be that hard to implement this yourself?
-
Here's a hint:
str.Substring(shiftAmount) + str.Substring(0, shiftAmount);
Do you really think it would be that hard to implement this yourself?
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
-
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
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.
-
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.
-
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.
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.
-
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.
-
Here's a hint:
str.Substring(shiftAmount) + str.Substring(0, shiftAmount);
Do you really think it would be that hard to implement this yourself?
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 ;
-
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 ;
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.