DilyaraL

ПолеГалуа

Apr 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int Mult(int a, int b, int f)//// Для 𝑎(𝑥), 𝑏(𝑥) возвращает 𝑐(𝑥)=𝑎(𝑥)∙𝑏(𝑥) 𝑚𝑜𝑑 𝑓(𝑥).
  6. {
  7. int t=0, mask=1;
  8. for (int i = 0; i < 8; i++)
  9. {
  10. if ((b&mask) != 0)
  11. t ^= a;
  12. if ((a & 128) == 0) a = a << 1;
  13. else a = (a << 1) ^ f;
  14. mask = mask << 1;
  15. }
  16. return t;
  17. }
  18.  
  19. int Power(int a, int b, int f)//// Возведение в степень: возвращает 𝑎(𝑥)^𝑏 𝑚𝑜𝑑 𝑓(𝑥).
  20. {
  21. int c=1;
  22. while (b > 0)
  23. {
  24. a = Mult(a, a, f);
  25. b = b >> 1;
  26. if (b % 2 == 0) c = Mult(c, a, f);
  27. }
  28. return c;
  29. }
  30.  
  31. int pow2(int n)//возводим 2 в степень n
  32. {
  33. int t=1;
  34. for (int i = 0; i < n; i++)
  35. t *= 2;
  36. return t;
  37. }
  38.  
  39. int Tr(int u)//след
  40. {
  41. int byte = 0;
  42. int p = 128;
  43. for (int i =0; i<8;i++)
  44. {
  45. if (u - p >= 0)
  46. {
  47. u = u - p;
  48. byte++;//колво единичек в двоичной записи
  49. }
  50. p = p / 2;
  51. }
  52. return (byte % 2);
  53. }
  54.  
  55. void root2(int a, int b, int f)//корни квадратного уравниения
  56. {
  57. int x1=0, x2=0;
  58. int u = 35, s;
  59. if (a == 0)
  60. {
  61. x1 = Power(a, 128, f);
  62. x2 = x1;
  63. }
  64. else
  65. {
  66. b = Mult(b, Power(a, 253, f), f);//b/a^2
  67. a = 1;
  68. if (Tr(b) == 0)
  69. {
  70. for (int i = 0; i < 8; i++)
  71. {
  72. s = 0;
  73. for (int j = 0; i < i; j++)
  74. {
  75. s += Power(u, pow2(j), f);
  76. }
  77. x1 = x1 ^ Power(b, pow2(i), f) ^ s;
  78. }
  79. x2 = 1 + x1;
  80. }
  81. }
  82. cout << "x1= " << x1 << endl << "x2= " << x2 << endl;
  83. }
  84.  
  85. int main()
  86. {
  87. int a = 164, b = 124, f = 285;
  88. root2(a, b, f);
  89. system("pause");
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment