DilyaraL

Поле

May 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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. if (b % 2 != 0) c = Mult(c, a, f);
  25. a = Mult(a, a, f);
  26. b = b >> 1;
  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;//Tr(u)=1
  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 = 1; i < 8; i++)
  71. {
  72. s = 0;
  73. for (int j = 0; j < i-1; 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. int main()
  85. {
  86. int a = 164, b = 124, f = 285;
  87. cout << "86*17= " << Mult(84, 17, f) << endl;
  88. cout << "2^6=";
  89. cout << Power(2, 6, f)<< endl;
  90. root2(a, b, f);
  91. cout << "x^2+" << a << "x+" << b << "=0" << endl;
  92. system("pause");
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment