From fb6052b2a4be48ca6f0d0eac4d9c32b29708755a Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 10 Feb 2021 13:36:06 +0700 Subject: Add ReverseInPlace methods --- crypto/src/util/Arrays.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crypto/src/util') diff --git a/crypto/src/util/Arrays.cs b/crypto/src/util/Arrays.cs index 57d79c0bb..784d45efb 100644 --- a/crypto/src/util/Arrays.cs +++ b/crypto/src/util/Arrays.cs @@ -804,6 +804,38 @@ namespace Org.BouncyCastle.Utilities return result; } + public static byte[] ReverseInPlace(byte[] a) + { + if (null == a) + return null; + + int p1 = 0, p2 = a.Length - 1; + while (p1 < p2) + { + byte t1 = a[p1], t2 = a[p2]; + a[p1++] = t2; + a[p2--] = t1; + } + + return a; + } + + public static int[] ReverseInPlace(int[] a) + { + if (null == a) + return null; + + int p1 = 0, p2 = a.Length - 1; + while (p1 < p2) + { + int t1 = a[p1], t2 = a[p2]; + a[p1++] = t2; + a[p2--] = t1; + } + + return a; + } + public static void Clear(byte[] data) { if (null != data) -- cgit 1.4.1