PasswordCryptography

08/16/2012 00:30 CriticallyDev#1
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 I don't have a username#2
08/16/2012 05:38 _tao4229_#3
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 ameralzlam10#4
shadow man123 3mel amrece
08/16/2012 19:48 CriticallyDev#5
Quote:
Originally Posted by I don't have a username View Post
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_ View Post
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 I don't have a username#6
Quote:
Originally Posted by CriticallyDev View Post
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.
No. I have no development experience :(. How do I code? :confused::confused::confused: :(:(:(:(
08/16/2012 21:36 InfamousNoone#7
Quote:
Originally Posted by _tao4229_ View Post
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 Spirited#8
Requesting something being closed isn't nearly as effective as reporting your own thread to be closed.