dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

Circular Shift for BitArray #46669

Open TourajOstovari opened 3 years ago

TourajOstovari commented 3 years ago

Background and Motivation

For Cryptography usage.

Proposed API

 namespace System.Collections
 {
     public partial class BitArray
     {
+        public void CircularShiftLeft(int times);
+        public void CircularShiftRight(int times);
+        public void LogicalShiftLeft(int times);
+        public void LogicalShiftRight(int times);
}

Usage Examples

BitArray A = new BitArray(1024, true);
A.CircularShiftLeft(15);

Risks

No Risks

Dotnet-GitSync-Bot commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 3 years ago

Tagging subscribers to this area: @eiriktsarpalis See info in area-owners.md if you want to be subscribed.

Issue Details
## Background and Motivation For Cryptography usage. ## Proposed API ```diff namespace System.Collections.BitArray { + public class BitArray { public void CircularShiftLeft(int times); public void CircularShiftRight(int times); public void LogicalShiftLeft(int times); public void LogicalShiftRight(int times); } ``` ## Usage Examples ``` C# BitArray A = new BitArray(1024, true); A.CircularShiftLeft(15); ``` ## Risks No Risks
Author: TourajOstovari
Assignees: -
Labels: `api-suggestion`, `area-System.Collections`, `untriaged`
Milestone: -
tannergooding commented 3 years ago

It's worth noting that BitArray already exposes LeftShift and RightShift, both of which are logical shifts.

CircularShift should likely be calls LeftRotate and RightRotate or RotateLeft and RotateRight. The former matches the naming convention already used by BitArray while the latter matches the names used in things like System.Numerics.BitOperations

TourajOstovari commented 3 years ago

ok please add in the method's xml comment RightShiftor LeftShiftare logical. BitOperations is not doing this operation on bitarray please. OK I CAN WAIT FOR .NET 6

TourajOstovari commented 3 years ago

Would we have RotateShiftor RotateRightmethods like built-in BitArray?

TourajOstovari commented 3 years ago

Hello, I want while doing Logical Shift via BitArray collection, enter ‘1’ instead ‘0’. Can you help me? Actually while I am using LeftShift or RightShift, enter number of counts and which bit should enter? like ‘0’ or ‘1’. Current default value of logical shift is ‘0’ bit. Thanks.

TourajOstovari commented 3 years ago

Hello, it could be better to have self defined matrix’s dimensions that contains numbers as Char ,HEX, Byte, Binary for cryptography. for example it can hold values and user can do rotate shift on rows and columns. also a method that is doing logical shift on current matrix and asks the value that user wants to enter while doing logical shift for example enter ‘FF’ and number of times while calling logical shift method (And which rows or columns should be shift as rotate or logical) current classes of Matrix with System.numeric namespace is limited and only user can define 3x3 and 4x4 matrix. it could be perfect doing XOR, AND … with matrix and define to apply (Binary operation be done) on columns or rows of target matrix, for example I have a matrix that each rows would be XOR with columns of target matrix or columns of current matrix would be XOR with rows of target matrix that user should choose it actually is self defined.