public Parameters(int popSize, EncodingInformation encoding, SelectionInformation selection, CrossoverInformation crossover, MutationInformation mutation, StoppingInformation stopping) { _populationSize = popSize; _encodingInfo = encoding; _selectionInfo = selection; _crossoverInfo = crossover; _mutationInfo = mutation; _stoppingInfo = stopping; }
private void InitGA() { popSize = Settings.s0; noGen = Settings.ngen; EncodingInformation enc = new EncodingInformation(n, EncodingType.RealValued); for (int i = 0; i < n; i++) { enc.MinValues[i] = Settings.minval; enc.MaxValues[i] = Settings.maxval; } SelectionInformation sel = new SelectionInformation { Type = SelectionType.Tournament, TournamentSize = 2, Elitism = 1 }; CrossoverInformation cro = new CrossoverInformation { Type = CrossoverType.ArithmeticInteger, Probability = 0.9 }; MutationInformation mut = new MutationInformation { Type = MutationType.Gaussian, StandardDeviation = Settings.sigma, Probability = Settings.pm }; StoppingInformation stop = new StoppingInformation { Type = StoppingType.Generations, MaxGenerations = noGen }; _parameters = new Parameters(popSize, enc, sel, cro, mut, stop); }
public IActionResult AesEncrypt([FromBody] AesViewModel viewModel) { var mode = int.Parse(viewModel.Mode); EncodingInformation keyEncoding = (EncodingInformation)int.Parse(viewModel.KeyEncoding); EncodingInformation IVEncoding = (EncodingInformation)int.Parse(viewModel.IVEncoding); EncodingInformation encoding = (EncodingInformation)int.Parse(viewModel.Encoding); CustomAes aes = new CustomAes() { CipherMode = (BlockCipherMode)mode }; byte[] key = null; byte[] iv = null; switch (keyEncoding) { case EncodingInformation.HEX: key = StringHelper.StringHexToByteArray(viewModel.Key.ToUpper()); break; case EncodingInformation.BINARY_STRING: key = StringHelper.BinaryStringToBytes(viewModel.Key); break; default: throw new ArgumentOutOfRangeException(); } switch (IVEncoding) { case EncodingInformation.HEX: iv = StringHelper.StringHexToByteArray(viewModel.IV.ToUpper()); break; case EncodingInformation.BINARY_STRING: iv = StringHelper.BinaryStringToBytes(viewModel.IV); break; default: throw new ArgumentOutOfRangeException(); } byte[] message = null; switch (encoding) { case EncodingInformation.ASCII: { message = Encoding.ASCII.GetBytes(viewModel.Message); break; } case EncodingInformation.HEX: { message = StringHelper.StringHexToByteArray(viewModel.Message); break; } case EncodingInformation.BINARY_STRING: { message = StringHelper.BinaryStringToBytes(viewModel.Message); break; } case EncodingInformation.BASE64: { message = Convert.FromBase64String(viewModel.Message); break; } default: throw new ArgumentOutOfRangeException(); } byte[] encrypted = null; try { encrypted = aes.Encrypt(message, key, iv); } catch (Exception e) { return(BadRequest(new { Result = false, Message = e.Message })); } return(Json(encrypted)); }
public IActionResult DesDecrypt([FromBody] DesViewModel viewModel) { var mode = int.Parse(viewModel.Mode); var messageEncoding = int.Parse(viewModel.Encoding); EncodingInformation keyEncoding = (EncodingInformation)int.Parse(viewModel.KeyEncoding); EncodingInformation IVEncoding = (EncodingInformation)int.Parse(viewModel.IVEncoding); byte[] message = null; try { message = Convert.FromBase64String(viewModel.Message); } catch (Exception) { string msg = "Niepoprawny format Base64!"; return(BadRequest(new { Result = false, Message = msg })); } byte[] key = null; byte[] iv = null; switch (keyEncoding) { case EncodingInformation.HEX: key = StringHelper.StringHexToByteArray(viewModel.Key); break; case EncodingInformation.BINARY_STRING: key = StringHelper.BinaryStringToBytes(viewModel.Key); break; default: throw new ArgumentOutOfRangeException(); } switch (IVEncoding) { case EncodingInformation.HEX: iv = StringHelper.StringHexToByteArray(viewModel.IV); break; case EncodingInformation.BINARY_STRING: iv = StringHelper.BinaryStringToBytes(viewModel.IV); break; default: throw new ArgumentOutOfRangeException(); } CustomDes aes = new CustomDes(viewModel.Padding) { CipherMode = (BlockCipherMode)mode }; byte[] decrypted = null; try { decrypted = aes.Decrypt(message, key, iv); } catch (Exception e) { return(BadRequest(new { Result = false, Message = e.Message })); } return(Json(decrypted)); }