/// <summary> /// 输入并返回置换盒 /// </summary> /// <returns></returns> static PSData[] InputPSData(int count) { List <PSData> result = new List <PSData>(); int inpuLength, outputLength; for (int i = 0; i < count; i++) { string length = Console.ReadLine(); string data = Console.ReadLine(); string[] lengths = length.Split(' '); inpuLength = int.Parse(lengths[0]); outputLength = int.Parse(lengths[1]); string[] datas = data.Split(' '); int[] temp = new int[datas.Length]; for (int j = 0; j < datas.Length; j++) { temp[j] = int.Parse(datas[j]); } PSData pSData = new PSData() { InputLength = inpuLength, OutputLength = outputLength, Data = temp }; result.Add(pSData); } return(result.ToArray()); }
/// <summary> /// 获取一个库存 /// </summary> public PSData this[int index] { get { PSData result = null; if (index >= 0 && index < Count) { result = m_Storages[index]; } return(result); } }
protected override BitArray Calculate(int dataIndex, BitArray op) { // 从PS库中取出置换Data PSData permute = Parser.PermuteSBoxStorage.Permute[dataIndex]; BitArray result = new BitArray(permute.OutputLength); for (int i = 0; i < permute.Data.Length; i++) { result[i] = op[permute.Data[i]]; } return(result); }
protected override BitArray Calculate(int dataIndex, BitArray op) { PSData sBox = Parser.PermuteSBoxStorage.SBox[dataIndex]; // 将op转为十进制 int opInt = Convert.ToInt32(BlockCipherUtil.BitArrayToString(op), 2); int resultInt = sBox.Data[opInt]; // 将temp转为二进制字符串 StringBuilder resultStr = new StringBuilder(Convert.ToString(resultInt, 2)); for (int i = resultStr.Length; i < sBox.OutputLength; i++) { resultStr.Insert(0, "0"); } BitArray result = BlockCipherUtil.StringToBitArray(resultStr.ToString()); return(result); }