left Circular shift ??
-
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.
-
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.
Yar, me too.