|
You last visited: Today at 03:55
Advertisement
PasswordCryptography
Discussion on PasswordCryptography within the CO2 Private Server forum part of the Conquer Online 2 category.
08/16/2012, 00:30
|
#1
|
elite*gold: 0
Join Date: May 2012
Posts: 87
Received Thanks: 4
|
PasswordCryptography
Hey everyone.
I was wondering if someone with development experience could explain to me what these written codes on Impulses Base mean and how they work.
The following codes are located inside the password cryptography class. I'm not asking for help however I would find a formal breakdown of the codes to be very helpful.
Code:
static UInt32 LeftRotate(UInt32 var, UInt32 offset)
{
UInt32 tmp1, tmp2;
offset &= 0x1f;
tmp1 = var >> (int)(32 - offset);
tmp2 = var << (int)offset;
tmp2 |= tmp1;
return tmp2;
}
Code:
static UInt32 RightRotate(UInt32 var, UInt32 offset)
{
UInt32 tmp1, tmp2;
offset &= 0x1f;
tmp1 = var << (int)(32 - offset);
tmp2 = var >> (int)offset;
tmp2 |= tmp1;
return tmp2;
}
Thanks a ton in return everyone ^^.
|
|
|
08/16/2012, 00:50
|
#2
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
|
|
|
|
08/16/2012, 05:38
|
#3
|
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
|
They're ways to implement roll left/roll right in C#.
Roll left and roll right are bitwise operations that are very similar to left shift and right shift respectively.
Say you have the 4-bit (just to make it simpler) binary number 1001b (in binary, not decimal), left shifting by 2 (as in 1001 << 2) moves the binary digits over two places to the left, but does not roll them over to the right. So this leaves 0100 in binary. Roll left on the other hand rolls the values from the front to the back, meaning 1001 rol 2 would shift it over two with the rollover, leaving 0101. I believe there's an asm instruction to for ror/rol but there's no C# operator corresponding to it (or an IL instruction either? Hybrid?).
That's as simple as I can explain it, but bear in mind the roll over will happen after 32 bits if you're using an int, instead of 4.
As for a breakdown, in the case of LeftRotate, it does a left shift by the amount specified, then just adds (Bitwise or) the part that rolls over.
|
|
|
08/16/2012, 06:12
|
#4
|
elite*gold: 0
Join Date: Aug 2012
Posts: 21
Received Thanks: 0
|
shadow man123 3mel amrece
|
|
|
08/16/2012, 19:48
|
#5
|
elite*gold: 0
Join Date: May 2012
Posts: 87
Received Thanks: 4
|
Quote:
Originally Posted by I don't have a username
|
I guess you don't have enough development experience as that's the first thing I searched and actually understood the concept of it's definition.
Quote:
Originally Posted by _tao4229_
They're ways to implement roll left/roll right in C#.
Roll left and roll right are bitwise operations that are very similar to left shift and right shift respectively.
Say you have the 4-bit (just to make it simpler) binary number 1001b (in binary, not decimal), left shifting by 2 (as in 1001 << 2) moves the binary digits over two places to the left, but does not roll them over to the right. So this leaves 0100 in binary. Roll left on the other hand rolls the values from the front to the back, meaning 1001 rol 2 would shift it over two with the rollover, leaving 0101. I believe there's an asm instruction to for ror/rol but there's no C# operator corresponding to it (or an IL instruction either? Hybrid?).
That's as simple as I can explain it, but bear in mind the roll over will happen after 32 bits if you're using an int, instead of 4.
As for a breakdown, in the case of LeftRotate, it does a left shift by the amount specified, then just adds (Bitwise or) the part that rolls over.
|
Thank you for that formal breakdown. I'll have another look at how it's used in the source.
P.S: This thread can be closed.
|
|
|
08/16/2012, 21:10
|
#6
|
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
|
|
|
|
08/16/2012, 21:36
|
#7
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
|
Quote:
Originally Posted by _tao4229_
They're ways to implement roll left/roll right in C#.
Roll left and roll right are bitwise operations that are very similar to left shift and right shift respectively.
Say you have the 4-bit (just to make it simpler) binary number 1001b (in binary, not decimal), left shifting by 2 (as in 1001 << 2) moves the binary digits over two places to the left, but does not roll them over to the right. So this leaves 0100 in binary. Roll left on the other hand rolls the values from the front to the back, meaning 1001 rol 2 would shift it over two with the rollover, leaving 0101. I believe there's an asm instruction to for ror/rol but there's no C# operator corresponding to it (or an IL instruction either? Hybrid?).
That's as simple as I can explain it, but bear in mind the roll over will happen after 32 bits if you're using an int, instead of 4.
As for a breakdown, in the case of LeftRotate, it does a left shift by the amount specified, then just adds (Bitwise or) the part that rolls over.
|
In assembly there is the ror and rol instructions. Even at the IL level, there is no instruction for either of these operators, so you must create a wrapper utilizing bit shifts and or to re-create them.
|
|
|
08/17/2012, 04:11
|
#8
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,191
|
Requesting something being closed isn't nearly as effective as reporting your own thread to be closed.
|
|
|
All times are GMT +1. The time now is 03:56.
|
|