Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Blum.hpp"
- #include "stdio.h"
- #include "stdlib.h"
- using namespace std;
- int losowe() //Generator wartosci x0
- {
- int a;
- random_device device;
- mt19937 generator(device());
- uniform_int_distribution<int> distribution(65, 122);
- a = distribution(generator);
- if (a > 90 && a < 97) { a = losowe(); } // eliminuje tutaj znaki inne niż litery
- return a;
- }
- //HugeInt power( HugeInt x, HugeInt y, HugeInt p)
- //{
- // HugeInt res = HugeInt("1"); /* wynik */
- //
- // x = x % p;
- // while (y > 0)
- // {
- // if (y%2 == 1) {
- // res *= x;
- // res = res % p;
- // }
- // x *= x;
- // x = x % p;
- // y /= 2;
- // }
- // return res;
- //}
- HugeInt modpow(HugeInt base, HugeInt exp, HugeInt modulus) {
- base = base % modulus;
- HugeInt result = 1;
- while (exp > 0) {
- if (exp % 2 == 1) result = (result * base) % modulus;
- base = (base * base) % modulus;
- exp /= 2;
- }
- return result;
- }
- vector<bool> BlumMicali( int dlugosc)
- {
- srand( time( NULL ) );
- HugeInt a = HugeInt("12360923874510234561092345619023465019234561092345601234965123495619234659123465901234650923456019432560923456109234650059360928365127965012397561230489751209571627389519659185234750129875104928502");
- HugeInt p = HugeInt("97512978125816728651326745927562561375169519415679951917625138884594562974219756961687292466758265957415675231498987423728564198147423285187561498415673281280265418907820596742182062749517488941522");
- a = HugeInt("23456190234650192345610923456012349651234956192346591234659012346509234560194325609232345619023465019234561092345601234965123495619234659123465901234650923456019432560923");
- p = HugeInt("99324320234650192345610923456012349651234956192346591234659012346509234560194325609232345619023465019234561092345601234965123495619234659123465901234650923456019432560923");
- HugeInt x0 = losowe();
- cout << x0 ;
- HugeInt x;
- vector<bool> klucz;
- for( int i=0; i < dlugosc * 8; i++)
- {
- x = modpow(a, x0, p);
- //cout << x << '\t';
- if( x > (p-1)/2 ) klucz.push_back(1);
- else klucz.push_back(0);
- x0 = x;
- }
- return klucz;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement