1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/src/util/Integers.cs b/crypto/src/util/Integers.cs
index 7d98de586..b243b88b2 100644
--- a/crypto/src/util/Integers.cs
+++ b/crypto/src/util/Integers.cs
@@ -1,5 +1,7 @@
using System;
+using Org.BouncyCastle.Math.Raw;
+
namespace Org.BouncyCastle.Utilities
{
public abstract class Integers
@@ -29,6 +31,20 @@ namespace Org.BouncyCastle.Utilities
return DeBruijnTZ[(uint)((i & -i) * 0x04D7651F) >> 27];
}
+ public static int Reverse(int i)
+ {
+ i = (int)Bits.BitPermuteStepSimple((uint)i, 0x55555555U, 1);
+ i = (int)Bits.BitPermuteStepSimple((uint)i, 0x33333333U, 2);
+ i = (int)Bits.BitPermuteStepSimple((uint)i, 0x0F0F0F0FU, 4);
+ return ReverseBytes(i);
+ }
+
+ public static int ReverseBytes(int i)
+ {
+ return RotateLeft((int)((uint)i & 0xFF00FF00U), 8) |
+ RotateLeft((int)((uint)i & 0x00FF00FFU), 24);
+ }
+
public static int RotateLeft(int i, int distance)
{
return (i << distance) ^ (int)((uint)i >> -distance);
|