Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int Mult(int a, int b, int f)//// Для 𝑎(𝑥), 𝑏(𝑥) возвращает 𝑐(𝑥)=𝑎(𝑥)∙𝑏(𝑥) 𝑚𝑜𝑑 𝑓(𝑥).
- {
- int t=0, mask=1;
- for (int i = 0; i < 8; i++)
- {
- if ((b&mask) != 0)
- t ^= a;
- if ((a & 128) == 0) a = a << 1;
- else a = (a << 1) ^ f;
- mask = mask << 1;
- }
- return t;
- }
- int Power(int a, int b, int f)//// Возведение в степень: возвращает 𝑎(𝑥)^𝑏 𝑚𝑜𝑑 𝑓(𝑥).
- {
- int c=1;
- while (b > 0)
- {
- a = Mult(a, a, f);
- b = b >> 1;
- if (b % 2 == 0) c = Mult(c, a, f);
- }
- return c;
- }
- int pow2(int n)//возводим 2 в степень n
- {
- int t=1;
- for (int i = 0; i < n; i++)
- t *= 2;
- return t;
- }
- int Tr(int u)//след
- {
- int byte = 0;
- int p = 128;
- for (int i =0; i<8;i++)
- {
- if (u - p >= 0)
- {
- u = u - p;
- byte++;//колво единичек в двоичной записи
- }
- p = p / 2;
- }
- return (byte % 2);
- }
- void root2(int a, int b, int f)//корни квадратного уравниения
- {
- int x1=0, x2=0;
- int u = 35, s;
- if (a == 0)
- {
- x1 = Power(a, 128, f);
- x2 = x1;
- }
- else
- {
- b = Mult(b, Power(a, 253, f), f);//b/a^2
- a = 1;
- if (Tr(b) == 0)
- {
- for (int i = 0; i < 8; i++)
- {
- s = 0;
- for (int j = 0; i < i; j++)
- {
- s += Power(u, pow2(j), f);
- }
- x1 = x1 ^ Power(b, pow2(i), f) ^ s;
- }
- x2 = 1 + x1;
- }
- }
- cout << "x1= " << x1 << endl << "x2= " << x2 << endl;
- }
- int main()
- {
- int a = 164, b = 124, f = 285;
- root2(a, b, f);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment