string[] variants = { "Камень", "Ножницы", "Бумага" }; var key = new byte[128]; var pc = new byte[4]; var gen = RandomNumberGenerator.Create(); gen.GetBytes(key); gen.GetBytes(pc); var hmac = new HMACSHA256(key); var ipc = BitConverter.ToUInt32(pc, 0) % (variants.Length); var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(variants[ipc])); Console.WriteLine("Компьютер сделал ход\nHMAC : " + (BitConverter.ToString(hash, 0))); Console.WriteLine("Ваш выбор:\n0 : Выход"); for (int i = 0; i < variants.Length; i++) Console.WriteLine((i + 1) + " : " + variants[i]); int player = 0; if (!int.TryParse(Console.ReadLine(), out player) || player < 0 || player > variants.Length) { Console.WriteLine("Некорректный ввод"); return; } else if (player == 0) return; player -= 1; if (ipc == player) Console.WriteLine("Ничья"); else if (((ipc + player) % 2 == 0 && ipc > player) || ((ipc + player) != 0 && player > ipc)) Console.WriteLine("Вы выйграли!"); else Console.WriteLine("Вы проиграли!"); Console.WriteLine("Ключ : " + (BitConverter.ToUInt32(key, 0))); Console.ReadLine(); 

The key output is wrong, what could be the problem?

  • Write in the question: input data and expected result. And why do you think that the result in the question code is wrong - gil9red
  • @ gil9red changed, look. I, by the key that displays, I can not check whether the progress of the computer was changed. - EgorKa

0