private void RoundFunction(UInt64[,] hashState, int round) { // SBox and MDS layer for (int i = 0; i < 2; i++) { SBox(hashState, i, 0, 2, 4, 6, SUBSTITUTION_BOX[round, i]); SBox(hashState, i, 1, 3, 5, 7, SUBSTITUTION_BOX[round, i + 2]); MDS(hashState, i); } // Swaping var layer = round % 7; if (layer < 6) { var swapper = _swappers[layer]; for (var row = 1; row < 8; row += 2) { hashState[row, 0] = swapper(hashState[row, 0]); hashState[row, 1] = swapper(hashState[row, 1]); } } else { UInt64 swap; for (var row = 1; row < 8; row += 2) { swap = hashState[row, 0]; hashState[row, 0] = hashState[row, 1]; hashState[row, 1] = swap; } } }
private static UInt64[,] State_Change(UInt64[,] State, Byte[] Message, UInt16 Rate_in_bytes) { int pos; for (Byte ib = 0; ib < 5; ++ib) { for (Byte jb = 0; jb < 5; ++jb) { pos = ib + jb * 5; // По умолчанию < 9, тк длина каждой подстроки 72 байта или 9 слов по 4 байта if (pos < (Rate_in_bytes / state_width_in_bytes)) { pos *= state_width_in_bytes; for (Byte i = 0; i < state_width_in_bytes; ++i) { State[ib, jb] ^= ((UInt64)(Message[pos + i]) << (i * 8)); } } else { break; } } } //Keccak_f for (Byte i = 0; i < rounds_number; i++) { State = Round(State, RC[i]); } return(State); }
/// <summary> /// Call to set result bit len and internal mode of operation /// </summary> /// <param name="bitLen">Bit len 224, 256, 384 and 512</param> public void Config(int bitLen) { switch (bitLen) { case 224: this._initState = JH224_H0; break; case 256: this._initState = JH256_H0; break; case 384: this._initState = JH384_H0; break; case 512: this._initState = JH512_H0; break; default: throw new ArgumentException(); } this._bitLen = bitLen; }
private void Bijective(UInt64[,] hashState) { for (int i = 0; i < 42; i++) { RoundFunction(hashState, i); } }
public ComplexData GetData(ref int x, ref int y, ref double[,] res, ref double[,] ims, ref double[,] other, ref UInt64[,] height) { m_hasOne.WaitOne(); x = m_tileX; y = m_tileY; res = m_res; ims = m_ims; other = m_other; height = m_height; ComplexData ret = m_data; m_gotOne.Set(); if (ret == null) { m_thread.Join(); m_thread = null; } m_tileX = 0; m_tileY = 0; m_data = null; m_res = null; m_ims = null; m_other = null; m_height = null; return ret; }
private static UInt64[,] Last_block_proc(UInt64[,] State, Byte[] MessageB, UInt16 Rate_in_bytes) { UInt16 delta = (UInt16)(Rate_in_bytes - MessageB.Length); Byte[] Pad_Message = new Byte[Rate_in_bytes]; int pos = 0; for (int i = 0; i < MessageB.Length; ++i) { Pad_Message[pos] = MessageB[i]; ++pos; } if (delta == 1) { Pad_Message[pos] = 0x86;//0x61;//0110 0001 } else { Pad_Message[pos] = 0x06;//0x60;//0110 0000 delta -= 2; while (delta > 0) { Pad_Message[pos + delta] = 0x00; --delta; } Pad_Message[Pad_Message.Length - 1] = 0x80;//0x01; } State_Change(State, Pad_Message, Rate_in_bytes); return(State); }
public static bool FindFreeSpaceForSwitch(NetworkModel networkModel, UInt64[,] grid, int indexI, int indexJ, int i, out int freeI, out int freeJ) { bool spaceFound = false; int step = 1; while (!spaceFound) { if (grid[indexI, (indexJ - step) % 1000] == 0) { indexJ = (indexJ - step) % 1000; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } else if (grid[(indexI - step) % 1000, (indexJ - step) % 1000] == 0) { indexI = (indexI - step) % 1000; indexJ = (indexJ - step) % 1000; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } else if (grid[(indexI - step) % 1000, indexJ] == 0) { indexI = (indexI - step) % 1000; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } else if (grid[indexI, (indexJ + step) % 1000] == 0) { indexJ = (indexJ + step) % 1000; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } else if (grid[(indexI + step) % 1000, (indexJ + step) % 1000] == 0) { indexI = (indexI + step) % 1000; indexJ = (indexJ + step) % 1000; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } else if (grid[(indexI + step) % 1000, indexJ] == 0) { indexI = (indexI + step) % 1000;; grid[indexI, indexJ] = networkModel.Switches[i].Id; spaceFound = true; } if (++step == 16) { break; } } freeI = indexI; freeJ = indexJ; return(spaceFound); }
private static void f(ref UInt64[,] S) { for (int round_number = 0; round_number < rounds_amount; round_number++) { UInt64[] C = { 0, 0, 0, 0, 0 }; UInt64[] D = { 0, 0, 0, 0, 0 }; UInt64[,] B = new UInt64[words_amount, words_amount]; for (int i = 0; i < words_amount; ++i) { for (int j = 0; j < words_amount; ++j) { B[i, j] = 0; } } ///THETA STEP/// for (int i = 0; i < words_amount; ++i) { C[i] = S[i, 0] ^ S[i, 1] ^ S[i, 2] ^ S[i, 3] ^ S[i, 4]; } for (int i = 0; i < words_amount; ++i) { D[i] = C[(i + 4) % words_amount] ^ cyclicShift(C[(i + 1) % 5], 1); } for (int i = 0; i < words_amount; ++i) { for (int j = 0; j < words_amount; ++j) { S[i, j] = S[i, j] ^ D[i]; } } ///PI STEP/// for (int i = 0; i < words_amount; ++i) { for (int j = 0; j < words_amount; ++j) { B[j, (2 * i + 3 * j) % 5] = cyclicShift(S[i, j], shift[i, j]); } } ///CHI STEP/// for (int i = 0; i < words_amount; ++i) { for (int j = 0; j < words_amount; ++j) { S[i, j] = B[i, j] ^ ((~B[(i + 1) % 5, j]) & B[(i + 2) % 5, j]); } } ///IOTA STEP/// S[0, 0] = S[0, 0] ^ RC[round_number]; } }
public ComplexData(double[,] res, double[,] ims, double[,] other, UInt64[,] height) { Real = res; Imaginary = ims; Other = other; Level = height; Loaded = true; AsComplex = new Helper(this); }
/// <summary> /// Maximum Distance Separable /// </summary> private void MDS(UInt64[,] hashState, int col) { hashState[1, col] ^= hashState[2, col]; hashState[3, col] ^= hashState[4, col]; hashState[5, col] ^= hashState[0, col] ^ hashState[6, col]; hashState[7, col] ^= hashState[0, col]; hashState[0, col] ^= hashState[3, col]; hashState[2, col] ^= hashState[5, col]; hashState[4, col] ^= hashState[1, col] ^ hashState[7, col]; hashState[6, col] ^= hashState[1, col]; // m0=0, m1=2, m2=4, m3=6, m4=1, m5=3, m6=5, m7=7 }
private static void BigEndianInvert(UInt64[,] array, int rowCount, int colCount) { for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colCount; c++) { var bytes = BitConverter.GetBytes(array[r, c]); Array.Reverse(bytes); array[r, c] = BitConverter.ToUInt64(bytes, 0); } } }
public static UInt64[,] InitGrid(NetworkModel networkModel, UInt64[,] grid, DrawingGroup drawingGroup, Canvas myCanvas) { for (int i = 0; i < 1000; i++) { for (int j = 0; j < 1000; j++) { grid[i, j] = 0; } } return(LoadNetworkModelToGrid(networkModel, grid, drawingGroup, myCanvas)); }
static ZobristHash() { rand = new Random(); hashtable = new UInt64[ChessSettings.boardSize * ChessSettings.boardSize, (int)ChessPieceTypeExtension.Total]; for (int i = 0; i < ChessSettings.boardSize * ChessSettings.boardSize; i++) { for (int j = 0; j < (int)ChessPieceTypeExtension.Total; j++) { hashtable[i, j] = GetRandomHash(rand); } } }
public ChessPosition() { initChessEval(); Board = new SquareInfo[64]; emptyBoard = new SquareInfo[64]; Princ = new ChessMove[maxDepth, maxDepth]; killers = new ChessMove[2, 1000]; mvvLva = new int[8, 8]; searchHistory = new int[16, 64]; // Init the mvvLva array for (int v = 0; v <= 6; v++) for (int a = 0; a <= 6; a++) mvvLva[v, a] = v * 100 +6 - a; // Init the killers array for (int i = 0; i < 1000; i++) { killers[0, i] = new ChessMove(new Square(99, 99), new Square(99, 99)); killers[1, i] = new ChessMove(new Square(99, 99), new Square(99, 99)); } // Init the emptyBoard and Board arrays for (int i = 0; i <= 63; i++) { emptyBoard[i] = new SquareInfo(Pieces.None, new Square(i)); Board[i] = emptyBoard[i]; } // Init the hashKeys Random rng = new Random(); pieceKeys = new UInt64[16, 64]; for (int p = 0; p <= 15; p++) for (int sq = 0; sq <= 63; sq++) pieceKeys[p, sq] = (UInt64)rng.Next() + ((UInt64)rng.Next() << 15) + ((UInt64)rng.Next() << 30) + ((UInt64)rng.Next() << 45) + ((UInt64)rng.Next() << 60); castleKeys = new UInt64[16]; for (int i = 0; i <= 15; i++) castleKeys[i] = (UInt64)rng.Next() + ((UInt64)rng.Next() << 15) + ((UInt64)rng.Next() << 30) + ((UInt64)rng.Next() << 45) + ((UInt64)rng.Next() << 60); sideKey = (UInt64)rng.Next() + ((UInt64)rng.Next() << 15) + ((UInt64)rng.Next() << 30) + ((UInt64)rng.Next() << 45) + ((UInt64)rng.Next() << 60); // Init the pvTable pvTable = new Dictionary<ulong, int>(); EpSquare = new Square(0, 0); white = new ToMoveData(PieceColour.White, new Piece(PieceType.Pawn, PieceColour.White), new Piece(PieceType.Knight, PieceColour.White), new Piece(PieceType.Bishop, PieceColour.White), new Piece(PieceType.Rook, PieceColour.White), new Piece(PieceType.Queen, PieceColour.White), new Piece(PieceType.King, PieceColour.White), 1, 7, 1, CastleFlags.Wks, CastleFlags.Wqs, new Square("e1"), new Square("h1"), new Square("a1")); black = new ToMoveData(PieceColour.Black, new Piece(PieceType.Pawn, PieceColour.Black), new Piece(PieceType.Knight, PieceColour.Black), new Piece(PieceType.Bishop, PieceColour.Black), new Piece(PieceType.Rook, PieceColour.Black), new Piece(PieceType.Queen, PieceColour.Black), new Piece(PieceType.King, PieceColour.Black), 6, 0, -1, CastleFlags.Bks, CastleFlags.Bqs, new Square("e8"), new Square("h8"), new Square("a8")); PossibleMoves = new Collection<ChessMove>(); MoveHistory = new Collection<ChessMove>(); undoStack = new Stack<ChessMove>(); NewGame(); }
private static void FindPlaceInGrid(UInt64[,] grid, int indexI, int indexJ, out int row, out int column) { bool spaceFound = false; int step = 1; while (!spaceFound) { if (grid[indexI, (indexJ - step) % 1000] == 0) { indexJ = (indexJ - step) % 1000; spaceFound = true; } else if (grid[(indexI - step) % 1000, (indexJ - step) % 1000] == 0) { indexI = (indexI - step) % 1000; indexJ = (indexJ - step) % 1000; spaceFound = true; } else if (grid[(indexI - step) % 1000, indexJ] == 0) { indexI = (indexI - step) % 1000; spaceFound = true; } else if (grid[indexI, (indexJ + step) % 1000] == 0) { indexJ = (indexJ + step) % 1000; spaceFound = true; } else if (grid[(indexI + step) % 1000, (indexJ + step) % 1000] == 0) { indexI = (indexI + step) % 1000; indexJ = (indexJ + step) % 1000; spaceFound = true; } else if (grid[(indexI + step) % 1000, indexJ] == 0) { indexI = (indexI + step) % 1000;; spaceFound = true; } if (++step == 16) { break; } } row = indexI; column = indexJ; }
private void Compress(UInt64[,] hashState, byte[] buffer) { var block = ToBlock(buffer); for (int i = 0; i < 8; i++) { hashState[i >> 1, i & 1] ^= block[i]; } Bijective(hashState); for (int i = 0; i < 8; i++) { hashState[(i + 8) >> 1, (i + 8) & 1] ^= block[i]; } }
public MatrixArrayGraph(IGenericPropertyGraph<UInt64, Int64, String, String, Object, UInt64, Int64, String, String, Object, UInt64, Int64, String, String, Object, UInt64, Int64, String, String, Object> PropertyGraph, UInt64 X, UInt64 Y) { this.PropertyGraph = PropertyGraph; this._MatrixGraph = new UInt64[X, Y]; PropertyGraph.Vertices().ForEach(v => { _MatrixGraph[v.Id - 1, 0] = (from e in v.OutEdges() select e.Id).ToArray().First(); }); }
private static UInt64[,] Round(UInt64[,] A, UInt64 RC_i) { Byte i, j; //Тета for (i = 0; i < 5; i++) { C[i] = A[i, 0] ^ A[i, 1] ^ A[i, 2] ^ A[i, 3] ^ A[i, 4]; } for (i = 0; i < 5; i++) { D[i] = C[(i + 4) % 5] ^ Rotate(C[(i + 1) % 5], 1, state_width); } for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { A[i, j] = A[i, j] ^ D[i]; } } //Ро и пи for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { B[j, (2 * i + 3 * j) % 5] = Rotate(A[i, j], offset[i, j], state_width); } } //Хи for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { A[i, j] = B[i, j] ^ ((~B[(i + 1) % 5, j]) & B[(i + 2) % 5, j]); } } //Йота A[0, 0] = A[0, 0] ^ RC_i; return(A); }
public VoxelMap(int width, int height, bool preFill = true) { this.map = new UInt64[width, height]; this.Width = width; this.Height = height; this.Depth = 64; if (preFill) { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { map[i, j] = UInt64.MaxValue; } } } }
private void InitByByte(UInt64[,] bybyte, UInt64 f) { for (int b = 0; b != 8; b++) { bybyte[b, 0] = 0; for (int i = 0x80; i != 0; i >>= 1) { bybyte[b, i] = f; f = this.poly[f & 1] ^ (f >> 1); } for (int i = 1; i != 256; i <<= 1) { UInt64 xf = bybyte[b, i]; for (int k = 1; k != i; k++) { bybyte[b, i + k] = xf ^ bybyte[b, k]; } } } }
void TransformBlock1024(UInt64[] s, UInt64[,] roundConstants, byte[] shiftTable) { const int cols = 16; int maskCols = cols - 1, maskCols8 = (maskCols << 3) | 7; UInt64[] t = new UInt64[16], u = new UInt64[32], pT = t, pU = u; Array.Copy(s, 0, u, 0, cols); for (int i = 0; i < 14; ++i) { for (int c = 0; c < cols; ++c) // AddRoundConstant { pU[c] ^= roundConstants[i, c]; } for (int c = 0; c < cols; ++c) { UInt64 col = 0; for (int row = 0; row < 8; ++row) { col ^= g_groestl_T_table[row, GetByte(pU, (c * 8 + shiftTable[8 + row]) & maskCols8)]; } pT[c] = col; } var tt = pT; pT = pU; pU = tt; } for (int c = 0; c < cols; ++c) { ulong v = pU[c]; for (int i = 0; i < 8; ++i) { m_state[c * 8 + i] ^= (byte)(v >> i * 8); } ; } }
private byte[] PlainHash(UInt64[,] hashState) { byte[] buffer = new byte[BUFFER_LEN * 2]; // 1024 bits or 128 bytes for (int row = 0; row < 8; row++) { for (int col = 0; col < 2; col++) { var bytes = BitConverter.GetBytes(hashState[row, col]); #if !BIGENDIAN Array.Reverse(bytes); #endif Buffer.BlockCopy(bytes, 0, buffer, (row << 4) + (col << 3), 8); } } int count = this._bitLen >> 3; int start = 128 - count; var result = new byte[count]; Buffer.BlockCopy(buffer, start, result, 0, count); return(result); }
public void Set2DuInt64() { string filename = GetFilename("set2duint64.h5"); Hdf5File file = Hdf5File.Create(filename); List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>(); Hdf5DimensionProperty property1 = new Hdf5DimensionProperty { CurrentSize = 2 }; properties.Add(property1); Hdf5DimensionProperty property2 = new Hdf5DimensionProperty { CurrentSize = 3 }; properties.Add(property2); Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.UInt64, properties); Assert.IsNotNull(dataset); UInt64[,] value = { { UInt64.MinValue, 0, UInt64.MaxValue }, { UInt64.MaxValue, 0, UInt64.MinValue } }; dataset.SetData(value); var array = dataset.GetData(); Assert.AreEqual(2, array.Rank); Assert.AreEqual(2, array.GetLength(0)); Assert.AreEqual(3, array.GetLength(1)); Assert.AreEqual(UInt64.MinValue, array.GetValue(0, 0)); Assert.AreEqual(0, array.GetValue(0, 1)); Assert.AreEqual(UInt64.MaxValue, array.GetValue(0, 2)); Assert.AreEqual(UInt64.MaxValue, array.GetValue(1, 0)); Assert.AreEqual(0, array.GetValue(1, 1)); Assert.AreEqual(UInt64.MinValue, array.GetValue(1, 2)); file.Close(); }
/// <summary> /// Substitution box /// </summary> private void SBox(UInt64[,] hashState, int col, int row0, int row1, int row2, int row3, UInt64 subs) { var m3 = ~hashState[row3, col]; var m2 = hashState[row2, col]; var m0 = hashState[row0, col] ^ (~m2 & subs); var m1 = hashState[row1, col]; var t0 = subs ^ (m0 & m1); m0 ^= m2 & m3; m3 ^= ~m1 & m2; m1 ^= m0 & m2; m2 ^= m0 & ~m3; m0 ^= m1 | m3; m3 ^= m1 & m2; m1 ^= t0 & m0; m2 ^= t0; hashState[row0, col] = m0; hashState[row1, col] = m1; hashState[row2, col] = m2; hashState[row3, col] = m3; }
private static Byte[] Squeezing(UInt64[,] State, UInt16 Rate_in_bytes) { Byte[] hash = new Byte[Rate_in_bytes]; byte[] temp = new Byte[8]; int pos, cur = 0; for (Byte jb = 0; jb < 5; ++jb) { for (Byte ib = 0; ib < 5; ++ib) { pos = ib + jb * 5; if (pos < (Rate_in_bytes / state_width_in_bytes)) { temp = BitConverter.GetBytes(State[ib, jb]); for (int j = 0; j < 8; ++j) { hash[cur + j] = temp[j]; } cur += 8; } } } return(hash); }
public static NetworkModel LoadNetworkModel(NetworkModel networkModel, UInt64[,] grid, Canvas myCanvas, MouseButtonEventHandler increase) { int counter = 0; networkModel = XmlHandler.Load <NetworkModel>(@"..\..\Geographic.xml"); // SUBSTATIONS for (int i = 0; i < networkModel.Substations.Count; i++) { double decimalX, decimalY; CoordinatesHandler.ToLatLon(networkModel.Substations[i].X, networkModel.Substations[i].Y, 34, out decimalX, out decimalY); int indexI, indexJ; CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ); if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.Substations[i].Id; networkModel.Substations[i].Row = indexI; networkModel.Substations[i].Column = indexJ; IndexesI.Add(indexI); IndexesJ.Add(indexJ); Entities.Add(networkModel.Substations[i].Id, networkModel.Substations[i]); } Ellipse image = ScreenHandler.DrawSubstationImage(indexI, indexJ, myCanvas, networkModel.Substations[i]); image.MouseLeftButtonDown += increase; networkModel.Substations[i].Shape = image; myCanvas.Children.Add(image); } // NODES for (int i = 0; i < networkModel.Nodes.Count; i++) { double decimalX, decimalY; CoordinatesHandler.ToLatLon(networkModel.Nodes[i].X, networkModel.Nodes[i].Y, 34, out decimalX, out decimalY); int indexI, indexJ; CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ); if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.Nodes[i].Id; } else { bool spaceFound = FindFreeSpaceForNode(networkModel, grid, indexI, indexJ, i, out indexI, out indexJ); grid[indexI, indexJ] = networkModel.Nodes[i].Id; if (!spaceFound) { counter++; } } networkModel.Nodes[i].Row = indexI; networkModel.Nodes[i].Column = indexJ; IndexesI.Add(indexI); IndexesJ.Add(indexJ); Entities.Add(networkModel.Nodes[i].Id, networkModel.Nodes[i]); Ellipse image = ScreenHandler.DrawNodeImage(indexI, indexJ, myCanvas, networkModel.Nodes[i]); image.MouseLeftButtonDown += increase; networkModel.Nodes[i].Shape = image; myCanvas.Children.Add(image); } // SWITCHES for (int i = 0; i < networkModel.Switches.Count; i++) { double decimalX, decimalY; CoordinatesHandler.ToLatLon(networkModel.Switches[i].X, networkModel.Switches[i].Y, 34, out decimalX, out decimalY); networkModel.Switches[i].X = decimalX; networkModel.Switches[i].Y = decimalY; int indexI, indexJ; CoordinatesHandler.FromCoordsToIndex(decimalX, decimalY, out indexI, out indexJ); if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.Switches[i].Id; } else { bool spaceFound = FindFreeSpaceForSwitch(networkModel, grid, indexI, indexJ, i, out indexI, out indexJ); grid[indexI, indexJ] = networkModel.Switches[i].Id; if (!spaceFound) { counter++; } } networkModel.Switches[i].Row = indexI; networkModel.Switches[i].Column = indexJ; IndexesI.Add(indexI); IndexesJ.Add(indexJ); Entities.Add(networkModel.Switches[i].Id, networkModel.Switches[i]); Ellipse image = ScreenHandler.DrawSwitchImage(indexI, indexJ, myCanvas, networkModel.Switches[i]); image.MouseLeftButtonDown += increase; networkModel.Switches[i].Shape = image; myCanvas.Children.Add(image); } int minI = IndexesI.Min(); // 672 int minJ = IndexesJ.Min(); // 726 int maxI = IndexesI.Max(); // 811 int maxJ = IndexesJ.Max(); // 951 return(networkModel); }
static int Main(string[] args) { Encryption_Module helpers = new Encryption_Module(); bool verbose = false; int num_cols = 8; const int pad_bytes = 2; var timer = new System.Diagnostics.Stopwatch(); // Validate inputs if (args.Length == 0) { Console.WriteLine("Usage: encrypt.exe [INPUT CSV DATA] [OUTPUT CSV] [OUTPUT PRIVATE KEY] [OUTPUT PUBLIC KEY]"); return(1); } // Load file locations String input_csv = args[0]; // String output_csv = args[1]; // String output_private_key = args[2]; // String output_public_key = args[3]; // Load CSV into 2D Array preProccessedData data = CSV_Loader(input_csv); // Process Data UInt64[,] processed_data = process_korea_format(data); BinaryWriter file_writer = new BinaryWriter(File.Open(args[1], FileMode.Create)); timer.Start(); // Loop over rows of data for (int i = 0; i <= processed_data.GetUpperBound(0); i++) //for (int i = 0; i <= 1; i++) { if (processed_data[i, 0] != 0) { // Print processed data if (verbose) { for (int k = 0; k < num_cols; k++) { Console.Write("{0} ", processed_data[i, k]); } Console.WriteLine(""); } // Store each row in bytes byte[] byted_row = new byte[num_cols * sizeof(UInt64)]; for (int j = 0; j < num_cols; j++) { Buffer.BlockCopy(BitConverter.GetBytes(processed_data[i, j]), 0, byted_row, j * sizeof(UInt64), sizeof(UInt64)); } // For each cell in the row for (int k = 0; k < num_cols; k++) { if (verbose) { //Console.WriteLine("Before Rand:"); ProcessBA(byted_row, k * sizeof(UInt64)); } // Pad 2 most significant bytes with random values RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(byted_row, sizeof(UInt64) - pad_bytes + k * sizeof(UInt64), pad_bytes); if (verbose) { //Console.WriteLine("After Rand:"); ProcessBA(byted_row, k * sizeof(UInt64)); } } //Encrypt Bytes: //Parallel encryption (speeds up from 2.8 s -> 1.3s) ParallelOptions po = new ParallelOptions(); po.MaxDegreeOfParallelism = 8; UInt64[] encrypted_values = new UInt64[num_cols]; //for (int current_cell = 0; current_cell < num_cols; current_cell++) Parallel.For(0, num_cols, po, (current_cell) => { UInt64 c_value_int = BitConverter.ToUInt64(byted_row, sizeof(UInt64) * current_cell); encrypted_values[current_cell] = helpers.encryptCell(c_value_int); Buffer.BlockCopy(BitConverter.GetBytes(encrypted_values[current_cell]), 0, byted_row, current_cell * sizeof(UInt64), sizeof(UInt64)); if (verbose) { //Console.WriteLine("After Rand:"); ProcessBA(byted_row, current_cell * sizeof(UInt64)); } }); // write row to file file_writer.Write(byted_row); } } timer.Stop(); // Close data files file_writer.Flush(); file_writer.Close(); Console.WriteLine($"Execution Time: {timer.ElapsedMilliseconds} ms"); return(0); }
private static UInt64[,] LoadNetworkModelToGrid(NetworkModel networkModel, UInt64[,] grid, DrawingGroup drawingGroup, Canvas myCanvas) { for (int i = 0; i < networkModel.substationEntities.Count; i++) { int indexI = networkModel.substationEntities[i].Row, indexJ = networkModel.substationEntities[i].Column; if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.substationEntities[i].Id; } else { GridHandler.FindPlaceInGrid(grid, indexI, indexJ, out indexI, out indexJ); grid[indexI, indexJ] = networkModel.substationEntities[i].Id; networkModel.substationEntities[i].Row = indexI; networkModel.substationEntities[i].Column = indexJ; } //ImageDrawing image = DrawingHandler.DrawSubstationImage(indexI, indexJ, myCanvas); //drawingGroup.Children.Add(image); } for (int i = 0; i < networkModel.nodeEntities.Count; i++) { int indexI = networkModel.nodeEntities[i].Row, indexJ = networkModel.nodeEntities[i].Column; if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.nodeEntities[i].Id; } else { GridHandler.FindPlaceInGrid(grid, indexI, indexJ, out indexI, out indexJ); grid[indexI, indexJ] = networkModel.nodeEntities[i].Id; networkModel.nodeEntities[i].Row = indexI; networkModel.nodeEntities[i].Column = indexJ; } //ImageDrawing image = DrawingHandler.DrawNodeImage(indexI, indexJ, myCanvas); //drawingGroup.Children.Add(image); } for (int i = 0; i < networkModel.switchEntities.Count; i++) { int indexI = networkModel.switchEntities[i].Row, indexJ = networkModel.switchEntities[i].Column; if (grid[indexI, indexJ] == 0) { grid[indexI, indexJ] = networkModel.switchEntities[i].Id; } else { GridHandler.FindPlaceInGrid(grid, indexI, indexJ, out indexI, out indexJ); grid[indexI, indexJ] = networkModel.switchEntities[i].Id; networkModel.switchEntities[i].Row = indexI; networkModel.switchEntities[i].Column = indexJ; } //ImageDrawing image = DrawingHandler.DrawSwitchImage(indexI, indexJ, myCanvas); //drawingGroup.Children.Add(image); } return(grid); }