Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] bruteforce searching
From: Radomir Szewczyk (radomir.szewczyk_at_[hidden])
Date: 2011-12-17 19:24:49


Hi all,
My problem is that I can't tell why my program hangs, maybe your
experienced eyes will see any dependancies making my program hang. I'm
really stuck.
I'll type the codes here (as there are 3 header files). Main code is
in test.cpp file. Functions used in test are in procedury1f.h. Test
uses only couple of functions from header files.

%%%%%%%%%%%%%%%%%%%%procedury1.h%%%%%%%%%%%%%%%%%%%%

void sboxABC();
unsigned char sbox(unsigned char d);
unsigned char obliczk2(unsigned char m1,unsigned char c1, unsigned char k1);
unsigned char szyfruj(unsigned char m,unsigned char k1, unsigned char k2);
unsigned char obliczk2plus(unsigned const char m1,unsigned const char
c1, unsigned const char k1);
unsigned char szyfrujplus(unsigned const char m,unsigned const char
k1, unsigned const char k2);
void sboxAES();
unsigned char obliczk2minus(unsigned const char m1,unsigned const char
c1, unsigned const char k1);
unsigned char szyfrujminus(unsigned const char m,unsigned const char
k1, unsigned const char k2);

%%%%%%%%%%%%%%%%%%%%procedury1f.h%%%%%%%%%%%%%%%%%%%%

void sboxABC()
// Sbox szyfru ABC-128
// int SBOX[256]
{
        int PSBOX[256]=
        {

                0x9E ,0xBC ,0xC3 ,0x82 ,0xA2 ,0x7E ,0x41 ,0x5A ,0x51 ,0x36 ,0x3F
,0xAC ,0xE3 ,0x68 ,0x2D ,0x2A,
                0xEB ,0x9B ,0x1B ,0x35 ,0xDC ,0x1E ,0x56 ,0xA5 ,0xB2 ,0x74 ,0x34
,0x12 ,0xD5 ,0x64 ,0x15 ,0xDD,
                0xB6 ,0x4B ,0x8E ,0xFB ,0xCE ,0xE9 ,0xD9 ,0xA1 ,0x6E ,0xDB ,0x0F
,0x2C ,0x2B ,0x0E ,0x91 ,0xF1,
                0x59 ,0xD7 ,0x3A ,0xF4 ,0x1A ,0x13 ,0x09 ,0x50 ,0xA9 ,0x63 ,0x32
,0xF5 ,0xC9 ,0xCC ,0xAD ,0x0A,
                0x5B ,0x06 ,0xE6 ,0xF7 ,0x47 ,0xBF ,0xBE ,0x44 ,0x67 ,0x7B ,0xB7
,0x21 ,0xAF ,0x53 ,0x93 ,0xFF,
                0x37 ,0x08 ,0xAE ,0x4D ,0xC4 ,0xD1 ,0x16 ,0xA4 ,0xD6 ,0x30 ,0x07
,0x40 ,0x8B ,0x9D ,0xBB ,0x8C,
                0xEF ,0x81 ,0xA8 ,0x39 ,0x1D ,0xD4 ,0x7A ,0x48 ,0x0D ,0xE2 ,0xCA
,0xB0 ,0xC7 ,0xDE ,0x28 ,0xDA,
                0x97 ,0xD2 ,0xF2 ,0x84 ,0x19 ,0xB3 ,0xB9 ,0x87 ,0xA7 ,0xE4 ,0x66
,0x49 ,0x95 ,0x99 ,0x05 ,0xA3,
                0xEE ,0x61 ,0x03 ,0xC2 ,0x73 ,0xF3 ,0xB8 ,0x77 ,0xE0 ,0xF8 ,0x9C
,0x5C ,0x5F ,0xBA ,0x22 ,0xFA,
                0xF0 ,0x2E ,0xFE ,0x4E ,0x98 ,0x7C ,0xD3 ,0x70 ,0x94 ,0x7D ,0xEA
,0x11 ,0x8A ,0x5D ,0x00 ,0xEC,
                0xD8 ,0x27 ,0x04 ,0x7F ,0x57 ,0x17 ,0xE5 ,0x78 ,0x62 ,0x38 ,0xAB
,0xAA ,0x0B ,0x3E ,0x52 ,0x4C,
                0x6B ,0xCB ,0x18 ,0x75 ,0xC0 ,0xFD ,0x20 ,0x4A ,0x86 ,0x76 ,0x8D
,0x5E ,0x01 ,0xED ,0x46 ,0x45,
                0xB4 ,0xFC ,0x83 ,0x02 ,0x54 ,0xD0 ,0xDF ,0x6C ,0xCD ,0x3C ,0x6A
,0xB1 ,0x3D ,0xC8 ,0x24 ,0xE8,
                0xC5 ,0x55 ,0x71 ,0x96 ,0x65 ,0x1C ,0x58 ,0x31 ,0xA0 ,0x26 ,0x6F
,0x29 ,0x14 ,0x1F ,0x6D ,0xC6,
                0x88 ,0xF9 ,0x69 ,0x0C ,0x79 ,0xA6 ,0x42 ,0xF6 ,0xCF ,0x25 ,0x9A
,0x10 ,0x9F ,0xBD ,0x80 ,0x60,
                0x90 ,0x2F ,0x72 ,0x85 ,0x33 ,0x3B ,0xE7 ,0x43 ,0x89 ,0xE1 ,0x8F
,0x23 ,0xC1 ,0xB5 ,0x92 ,0x4F
        };
        int i;
        for(i=0;i<256;i++) SBOX[i]=PSBOX[i];
} // sboxABC *********************************

void sboxAES()
// Sbox szyfru ABC-128
// int SBOX[256]
{
        int PSBOX[256]=
        {
                0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
                0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
                0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
                0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
                0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
                0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
                0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
                0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
                0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
                0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
                0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
                0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
                0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
                0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
                0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
                0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
                0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
                0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
                0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
                0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
                0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
                0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
                0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
                0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
                0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
                0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
                0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
                0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
                0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
                0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
                0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
                0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16

        };
        int i;
        for(i=0;i<256;i++) SBOX[i]=PSBOX[i];
} // sboxAES *********************************

unsigned char sbox(unsigned char d)
// Realizuje podstawienie w S-boksie
// int SBOX[256]
{
        unsigned char e;
        //unsigned g;
        e=SBOX[d];
        //g=e;
        return(e);
}; //sbox *************************************************

//k2=obliczk2(m1,c1,k1);

unsigned char obliczk2(unsigned char m1,unsigned char c1, unsigned char k1)
{
        unsigned char d;
        d=m1^k1;
        d=sbox(d);
        d=d^c1;
        return d;
}

//c2x=szyfruj(m2,k1,k2);

unsigned char szyfruj(unsigned char m,unsigned char k1, unsigned char k2)
{
        unsigned char d;
        d=m^k1;
        d=sbox(d);
        d=d^k2;
        return d;
}

unsigned char obliczk2plus(unsigned const char m1,unsigned const char
c1, unsigned const char k1)
{
        unsigned char d;
        d=m1+k1;
        d=sbox(d);
        d=d-c1;
        return d;
}
unsigned char obliczk2minus(unsigned const char m1,unsigned const char
c1, unsigned const char k1)
{
        unsigned char d;
        d=m1+k1;
        d=sbox(d);
        d=c1-d;
        return d;
}

//c2x=szyfruj(m2,k1,k2);

unsigned char szyfrujplus(unsigned const char m,unsigned const char
k1, unsigned const char k2)
{
        unsigned char d;
        d=m+k1;
        d=sbox(d);
        d=d-k2;
        return d;
}

unsigned char szyfrujminus(unsigned const char m,unsigned const char
k1, unsigned const char k2)
{
        unsigned char d;
        d=m-k1;
        d=sbox(d);
        d=d+k2;
        return d;
}

void losujpary()
{
        int m,c,ll,takisam,k;
        ll=0;
        m=rand()%256;
        c=rand()%256;
        tm[ll]=m;
        tc[ll]=c;
        ll=ll+1;

        while(ll<ilepar)
        {
                m=rand()%256;
                c=rand()%256;
                takisam=0;
                for(k=0;k<ll;k++)
                        if((tm[k]==m)||(tc[k])==c)takisam=1;
                if(takisam==0)
                {
                        tm[ll]=m;
                        tc[ll]=c;
                        ll=ll+1;
                }
        }
        // koniec losowania *******************
}//losujpary()

%%%%%%%%%%%%%%%%%%%%test.cpp%%%%%%%%%%%%%%%%%%%%

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "zmienneglobalne.h"
#include "procedury1.h"
#include "procedury1f.h"
#include "mpi.h"

int rank, size;

int main(int argc, char** argv)
{
        clock_t przed ,po;
        unsigned int im1,im2,ic1,ic2;
        unsigned char k1,k2,m1,m2,c1,c2,c2x;
        int l,licznik,l2;
    unsigned long int tabl[256];
        long int tablmax;
        sboxABC();
        printf("\nLamanie PP-1 1-rundowego - + 29.10.2010\n");
        tablmax=0;
        MPI_Status status;
        MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    printf("Hello world from process %d of %d.\n", rank, size);
        if(rank == 0)
        {
                przed = clock();
                for(int i = 0; i < 256; i++)
                {
                        tabl[i] = 0;
                }
                MPI_Barrier(MPI_COMM_WORLD);
                for(int proc = 1; proc < size; proc++)
                {
                        MPI_Send(&tabl,256,MPI_INT,proc,0,MPI_COMM_WORLD);
                }
        }
        else
        {
                MPI_Barrier(MPI_COMM_WORLD);
                MPI_Recv(&tabl,256,MPI_INT,0,0,MPI_COMM_WORLD, &status);
        }

                for(im1=rank;im1<=255;im1=im1+size)
                {
                        printf("\n%d ",im1);
                        for(ic1=0;ic1<=255;ic1++)
                                for(im2=im1+1;im2<=255;im2++)
                                        for(ic2=0;ic2<=255;ic2++)
                                        {
                                                m1=im1;
                                                c1=ic1;
                                                m2=im2;
                                                c2=ic2;
                                                if(c1!=c2)
                                                {
                                                        licznik=0;
                                                        for(l=0;l<256;l++)
                                                        {
                                                                k1=l;
                                                                k2=obliczk2minus(m1,c1,k1);
                                                                c2x=szyfrujminus(m2,k1,k2);
                                                                if(c2x==c2)licznik=licznik+1;
                                                                //printf("\n %x %x", c2x, c1);
                                                                //printf("%02x %02x ",k1,k2);
                                                        }
                                                        tabl[licznik]=tabl[licznik]+1;
                                                        if(licznik>tablmax)tablmax=licznik;
                                                }
                                        }
                                for(l2=0;l2<=tablmax;l2++)
                                printf("\n %d %lu",l2,tabl[l2]);
                }
                for(l2=0;l2<=tablmax;l2++)
                printf("\n %d %lu",l2,tabl[l2]);
                
        printf("Koniec: %d", rank);
        MPI_Barrier(MPI_COMM_WORLD);
        if(rank == 0) po = clock();
    MPI_Finalize();
        if(rank == 0) printf("\n %f sekund\n",
((float)(po-przed))/(float)CLOCKS_PER_SEC);
    return 0;
}

much appreciate your help.
Cheers
Radomir Szewczyk