Пример #1
0
int main() {
    std::string iv_str, message_str, fake_str;

    std::getline(std::cin, iv_str);
    std::getline(std::cin, message_str);
    std::getline(std::cin, fake_str);

    uint8_vec iv = hex_to_codes(iv_str);
    uint8_vec m(message_str.begin(), message_str.end());
    uint8_vec fake(fake_str.begin(), fake_str.end());

    std::cout << codes_to_hex(xor_vec(iv, xor_vec(m, fake))) << std::endl;

    return 0;
}
Пример #2
0
void adj_matrix::show(const list<vector<int>> &new_neutral_bits_set, const message &M1, const message &M2, const difference &D){
	int z = 0, x = 0;
	for (auto it = new_neutral_bits_set.begin(); it != new_neutral_bits_set.end(); it++) {
		x = 0;
		for (auto q = new_neutral_bits_set.begin(); q != new_neutral_bits_set.end(); q++) {
			const message_cupple tmp(xor_vec(M1.W, *it, *q), xor_vec(M2.W, *it, *q), R);
			if (D.equal(tmp, R) == R){
				adj[z][x] = 1;
			}
			cout << adj[z][x] << " ";
			x++;
		}
		cout << endl;
		z++;
	}
}
Пример #3
0
void printGoodBits(const message &M1, const message &tmp1, ofstream& changes){
	vector<int> v =  convert_vector_long(xor_vec(M1.W, tmp1.W));
	for (int i = 0; i < v.size(); i++){
		changes << v[i] << " ";
		cout << v[i] << " ";
	}
	cout << endl << endl;
}
Пример #4
0
void adj_matrix::fill(const vector<vector<int>> &v, const message &M1, const message &M2, const difference &D, const DifferentialPath &P){
	int z = 0;
	omp_set_num_threads(16);

#pragma omp parallel for
	for (z = 0; z < v.size(); z++) {
		message tmp_m1(M1);
		message tmp_m2(M2);
		for (int x = z; x < v.size(); x++) {
			tmp_m1.modify(xor_vec(M1.W, v[z], v[x]), R);
			tmp_m2.modify(xor_vec(M2.W, v[z], v[x]), R);
			if ((P.check(tmp_m1, tmp_m2) >= R) && (not_intersect(v[z], v[x]))){
				adj[z][x] = 1;
				adj[x][z] = 1;
			}
			if (x == z){
				adj[z][x] = 1;
			}
		}
		if ((z + 1) % 100 == 0)
			cout << z + 1 << " ";
	}
}
Пример #5
0
void construct_neutral_set(const message &M1, const message &M2, const difference &D, const DifferentialPath &P){
	int r = 0;
	set<vector<int>> bad_pairs;
	//read(bad_pairs);

	//cout << "bad set size: " << bad_pairs.size() << endl;

	ofstream pairs("pairs.txt");
	set<int> bad_set;
	for (int v = 0; v < 512; v++){
		if (P.checkBit(v)){
			message tmp_m1(M1);
			message tmp_m2(M2);
			tmp_m1.modify(xor_vec(M1.W, v, -1, -1, -1, -1), R);
			tmp_m2.modify(xor_vec(M2.W, v, -1, -1, -1, -1), R);
			if (P.check(tmp_m1, tmp_m2) >= R){
				#pragma omp critical
				{
					pairs << v << " -1 -1 -1 -1" << endl;
					bad_set.insert(v);
				}
			}
		}
	}

	time_t seconds = time(NULL);

	omp_set_num_threads(16);

	//*
	#pragma omp parallel for
	for (int v = 0; v < 512; v++){
		if (P.checkBit(v)){
			message tmp_m1(M1);
			message tmp_m2(M2);
			if (bad_set.find(v) == bad_set.end()){
				for (int q = v + 1; q < 512; q++){
					if (P.checkBit(q) && (bad_set.find(q) == bad_set.end())){
						tmp_m1.modify(xor_vec(M1.W, v, q, -1, -1, -1), R);
						tmp_m2.modify(xor_vec(M2.W, v, q, -1, -1, -1), R);
						if (P.check(tmp_m1, tmp_m2) >= R){
							#pragma omp critical
							{
								pairs << v << " " << q << " -1 -1 -1" << endl;
								//bad_pairs.insert(vector<int>{v,q});
							}
						}
					}
				}
			}
		}
	}
	//*/

	//cout << "pairs time: " << time(NULL) - seconds << endl;
	seconds = time(NULL);

	//*
	#pragma omp parallel for
	for (int v = 0; v < 512; v++){
		if (P.checkBit(v)){
			message tmp_m1(M1);
			message tmp_m2(M2);
			if (bad_set.find(v) == bad_set.end()){
				for (int q = v + 1; q < 512; q++){
					if (P.checkBit(q) && (bad_set.find(q) == bad_set.end())
						//&& (bad_pairs.find({ v, q }) == bad_pairs.end())
						){
						for (int w = q + 1; w < 512; w++){
							if (P.checkBit(w) && (bad_set.find(w) == bad_set.end())
								//&& (bad_pairs.find({ v, w }) == bad_pairs.end()) 
								//&& (bad_pairs.find({ q, w }) == bad_pairs.end())
								){
								tmp_m1.modify(xor_vec(M1.W, v, q, w, -1, -1), R);
								tmp_m2.modify(xor_vec(M2.W, v, q, w, -1, -1), R);
								if (P.check(tmp_m1, tmp_m2) >= R){
									#pragma omp critical
									{
										pairs << v << " " << q << " " << w << " -1 -1" << endl;
										//bad_pairs.insert(vector<int>{v, q, w});
									}
								}
							}
						}
					}
				}
			}
		}
		//cout << time(NULL) - t << " ";
	}
	//*/
	//cout << dec << "triplets time: " << time(NULL) - seconds << endl;

	seconds = time(NULL);

	//*
	#pragma omp parallel for
	for (int v = 0; v < 512; v++){
		if (P.checkBit(v)){
			message tmp_m1(M1);
			message tmp_m2(M2);
			if (bad_set.find(v) == bad_set.end()){
				for (int q = v + 1; q < 512; q++){
					if (P.checkBit(q) && (bad_set.find(q) == bad_set.end())){
						for (int w = q + 1; w < 512; w++){
							if (P.checkBit(w) && (bad_set.find(w) == bad_set.end())){
								for (int s = w + 1; s < 512; s++){
									if (P.checkBit(s) && (bad_set.find(s) == bad_set.end())){
										tmp_m1.modify(xor_vec(M1.W, v, q, w, s, -1), R);
										tmp_m2.modify(xor_vec(M2.W, v, q, w, s, -1), R);
										if (P.check(tmp_m1, tmp_m2) >= R){
											#pragma omp critical
											{
												pairs << v << " " << q << " " << w << " " << s << " -1" << endl;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		//cout << time(NULL) - t << " ";
	}

	//*/
	//cout << "quadroplets time: " << time(NULL) - seconds << endl;

	pairs.close();
}