Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <vector>
- #include "cstdlib"
- #include <map>
- #include <cmath>
- #include <stdint.h>
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <windows.h>
- #define R operator &(T a, S b);
- #define R operator ^(T a, S b);
- #define SizeOfVector 4
- #define CountOfFunc (pow(2, SizeOfVector))
- using namespace std;
- uint32_t mask = CountOfFunc - 1;
- uint32_t SBOXGeneral[] =
- { 0x06, 0x00,0x04,0x0d,0x09, 0x0a, 0x0f,0x02,0x05, 0x08, 0x0c,0x0e,0x01, 0x07, 0x03, 0x0b };
- uint32_t SBOX[] =
- { 0x00, 0x01, 0x02, 0x0c, 0x09, 0x0d, 0x03, 0x0f, 0x05, 0x0e, 0x0a, 0x0b, 0x04, 0x07, 0x06, 0x08 };
- int multiVect(uint32_t a) {
- uint32_t i;
- for (i = 0; a; a >>= 1) {
- i += a & 1;
- }
- if (i % 2 == 0) {
- return 0;
- }
- else {
- return 1;
- }
- }
- double getPropabilityForLinear(uint32_t alpha, uint32_t beta) {
- int count = 0;
- for (uint32_t x = 0x00; x < CountOfFunc; x++) {
- if (multiVect(alpha & x & mask) == multiVect(beta & SBOX[x] & mask)) {
- count++;
- }
- }
- return (double)count;
- }
- double linearСharacteristic() {
- uint32_t bestAlpha = 0;
- uint32_t bestBeta = 0;
- double bestPropability = 0;
- double temp = 0;
- for (uint32_t alpha = 0x1; alpha < CountOfFunc; alpha++) {
- for (uint32_t beta = 0x1; beta < CountOfFunc; beta++) {
- temp = ((getPropabilityForLinear(alpha & mask, beta & mask)));
- cout << temp / CountOfFunc << " ";
- if (abs(temp) >= bestPropability) {
- bestPropability = abs(temp);
- bestAlpha = alpha;
- bestBeta = beta;
- }
- }
- cout << endl;
- }
- return bestPropability * pow(2, SizeOfVector - 1);
- }
- int main() {
- linearСharacteristic();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement