Wednesday, 11 May 2016

QOS in OLSR

MP-OLSR is a multipath routing protocol based on OLSR. The Multipath Dijkstra Algorithm is proposed to obtain multiple paths. The algorithm gains great flexibility and extensibility by employing different link metrics and cost functions. In addition, route recovery and loop detection are implemented in MP-OLSR in order to improve quality of service regarding OLSR. The backward compatibility with OLSR based on IP source routing is also supported. 

MP-OLSR implementaion for Qualnet simulator

The MP-OLSR is implemented for Qualnet simulations. It is an extension of nOLSRv2. It exsits as an "add-on" in the Qualnet simulator.
About adding a new routing protocol in Qualnet, please refer to Qualnet Programmer's Guide.
MP-OLSR is an application-layer routing protocol based on OLSRv2, but it need to receive the data packet to read/modify the source routing packet header. To enable the application layer routing protocol MP-OLSR can handle the data packet, an MPOLSRRouterFunction is defined. And NetworkIpSetRouterFunction is used to register MPOLSRRouterFunction. This enables IP to directly call MPOLSRRouterFunction to determine the route for a packet if MP-OLSR is running at that interface.
Source code available:
Reference information:

MP-OLSR implementation for NS2 simulator

The MP-OLSR is implemented for NS2 simulations. It is an extension of um-OLSR.
About adding a new routing protocol in NS2, please refer to "Implementing a New Manet Unicast Routing Protocol in ns2",
Source code available:
Reference information:
The code is implemented based on v2.29. For those who have problem in installing the code, can try to downloadthe whole ns2 folder.
A sample of the tcl script is also available here.

Saturday, 7 May 2016

Ciphers

Description for Ciphers

Symmetric Ciphers Online allows you to encrypt or decrypt arbitrary message using several well known symmetric encryption algorithms such as AES, 3DES, or BLOWFISH.
Symmetric ciphers use the same (or very similar from the algorithmic point of view) keys for both encryption and decryption of a message. They are designed to be easily computable and able to process even large messages in real time. Symmetric ciphers are thus convenient for usage by a single entity that knows the secret key used for the encryption and required for the decryption of its private data – for example file system encryption algorithms are based on symmetric ciphers. If symmetric ciphers are to be used for secure communication between two or more parties problems related to the management of symmetric keys arise. Such problems can be solved using a hybrid approach that includes using asymmetric ciphers. Symmetric ciphers are basic blocks of many cryptography systems and are often used with other cryptography mechanisms that compensate their shortcomings.
Symmetric ciphers can operate either in the block mode or in the stream mode. Some algorithms support both modes, others support only one mode. In the block mode, the cryptographic algorithm splits the input message into an array of small fixed-sized blocks and then encrypts or decrypts the blocks one by one. In the stream mode, every digit (usually one bit) of the input message is encrypted separately.
In the block mode processing, if the blocks were encrypted completely independently the encrypted message might be vulnerable to some trivial attacks. Obviously, if there were two identical blocks encrypted without any additional context and using the same function and key, the corresponding encrypted blocks would also be identical. This is why block ciphers are usually used in various modes of operation. Operation modes introduce an additional variable into the function that holds the state of the calculation. The state is changed during the encryption/decryption process and combined with the content of every block. This approach mitigates the problems with identical blocks and may also serve for other purposes. The initialization value of the additional variable is called the initialization vector. The differences between block ciphers operating modes are in the way they combine the state (initialization) vector with the input block and the way the vector value is changed during the calculation. The stream ciphers hold and change their internal state by design and usually do not support explicit input vector values on their input.
Security note: Data are transmitted over the network in an unencrypted form! Please do not enter any sensitive information into the form above as we cannot guarantee you that your data won't be compromised.

Usage

Using the Input type selection, choose the type of input – a text string or a file. In case of the text string input, enter your input into theInput text textarea1,2. Otherwise, use the "Browse" button to select the input file to upload. Then select the cryptographic function you want to use in the Function field. Depending on the selected function the Initialization vector (IV) field is shown or hidden. Initialization vector is always a sequence of bytes, each byte has to be represented in hexadecimal form.
Select the operation mode in the Mode field and enter a key in the Key field. The permitted lengths of keys for particular cryptographic functions are listed below. If you don't specify a key with permitted length the key is prolonged with the proper number of null bytes at the end. When the key is changed the prefix of sha1(key) function is automatically filled in the IV field. You still may change the IV. The feature is intended only for your convenience. Using the radio buttons under the Key input field, you can specify whether the entered key value should be interpreted as a plain text or a hexadecimal value.
Finally, click the "Encrypt!" button or the "Decrypt!" button depending on whether you want the input message to be encrypted or decrypted.
The output message is displayed in a hex view and can also be downloaded as a binary file. The format of output file is simply a dump of binary data. The initialization vector is added to the file name for convenience.
Cryptographic functionKey lengthsInitialization vector lengths (all modes)
In bytesIn bitsIn bytesIn bits
AES16, 24 or 32128, 192 or 25616128
DES1 to 8 bytes8 to 6416128
TRIPLEDES1 to 248 to 19216128
BLOWFISH1 to 568 to 44816128
BLOWFISH-compat1 to 568 to 44816128
RIJNDAEL-2561 to 328 to 25664512
R41 to 2568 to 2048--
SERPENT1 to 328 to 25632256
TWOFISH1 to 328 to 25632256

1 You can use only hexadecimal characters, newlines, tabulators and new line characters if you decrypt a string.
2 Input text has an autodetect feature at your disposal. The autodetect detects for you if the content of Input text field is in form of a plain text or a hexadecimal string. You can turn off the feature by clicking on 'OFF' or by changing current type of input under the Input textfield.

Limits

The maximal size of the the text string input is 131,072 characters. The maximal size of the input file is 2,097,152 bytes.
DES Encryption
https://www.tools4noobs.com/

JNTUH Syllabus R13

Syllabus R13 CSE JNTUH
 Download

Change of blog address

Dear Members The name of our blog will be changed to gnitcsehyd.blogspot..com with effective from 8-5-2015

Monday, 25 April 2016

Important Announcement

Dear Readers/Members

The site name imraan-prrec.blogspot.com will be changed to gnitcsehyd.blogspot.com effectively from 30-4-2016.

Thursday, 7 April 2016

RSA Algorithm

 //RSA ALGORITHM  
 #include <stdio.h>  
 int modulo(int e, int n, int pt)  
 {  
   int h;  
   if(e==0)  
     return 1;  
   else if(e==1)  
     return pt%n;  
   else  
   {  
     h = modulo(e/2, n, pt);  
     if(e%2==0)  
       return ((h*h)%n)%n;  
     else  
       return ((h*h)*(pt%n))%n;  
   }  
 }  
 int main()  
 {  
   int p, q, n, z, e, d, pt,ct;  
   printf("Enter p & q values <prime numbers>: ");  
   scanf("%d%d", &p, &q);  
   n = p*q;  
   z = (p-1)*(q-1);  
   printf("\nEnter a relative prime number to %d i.e., e value: ",z);  
   scanf("%d", &e);  
   d = 1;  
   while((d*e)%z!=1)  
     d++;  
   printf("d value is: %d\n", d);  
   printf("Keys are: <e, n>:(%d, %d)\t<d, n>:(%d, %d)",e,n,d,n);  
   printf("\n\nEnter message<pt> such that pt < %d : ",n);  
   scanf("%d", &pt);  
   ct = modulo(e,n,pt);  
   printf("\nCipher Text: %d\n",ct);  
   pt = modulo(d,n,ct);  
   printf("Decrypted Text: %d",pt);  
   return 0;  
 }  
 /*  SAMPLE OUTPUT
 Enter p & q values <prime numbers>: 11 7  
 Enter a relative prime number to 60 i.e., e value: 13  
 d value is: 37  
 Keys are: <e, n>:(13, 77)    <d, n>:(37, 77)  
 Enter message<pt> such that pt < 77 : 5  
 Cipher Text: 26  
 Decrypted Text: 5  
 */  

Dijkstra's Algorithm 

/PROGRAM FOR DIJKSTRA'S ALGORITHM  
 #include <stdio.h>  
 #include <conio.h>  
 #define GRAPHSIZE 2048  
 #define INFINITY GRAPHSIZE*GRAPHSIZE  
 #define MAX(a, b) ((a > b) ? (a) : (b))  
 int e; /* The number of nonzero edges in the graph */  
 int n; /* The number of nodes in the graph */  
 long dist[GRAPHSIZE][GRAPHSIZE]; /* dist[i][j] is the distance between node i and j; 
 or 0 if there is no direct connection */  
 long d[GRAPHSIZE]; 
 /* d[i] is the length of the shortest path between the source (s) and node i */  
 int prev[GRAPHSIZE]; /* prev[i] is the node that comes right before i in 
 the shortest path from the source to i*/  
 void printD() {  
      int i;  
      printf("Distances:\n");  
      for (i = 1; i <= n; ++i)  
           printf("%d\t", i);  
      printf("\n");  
      for (i = 1; i <= n; ++i) {  
           printf("%ld\t", d[i]);  
      }  
      printf("\n");  
 }  
 /* Prints the shortest path from the source to dest.  
  * dijkstra(int) MUST be run at least once BEFORE this is called */  
 void printPath(int dest) {  
      if (prev[dest] != -1)  
           printPath(prev[dest]);  
      printf("%d ", dest);  
 }  
 void dijkstra(int s) {  
      int i, k, mini;  
      int visited[GRAPHSIZE];  
      for (i = 1; i <= n; ++i) {  
           d[i] = INFINITY;  
           prev[i] = -1; /* no path has yet been found to i */  
           visited[i] = 0; /* the i-th element has not yet been visited */  
      }  
      d[s] = 0;  
      for (k = 1; k <= n; ++k) {  
           mini = -1;  
           for (i = 1; i <= n; ++i)  
                if (!visited[i] && ((mini == -1) || (d[i] < d[mini])))  
                     mini = i;  
           visited[mini] = 1;  
           for (i = 1; i <= n; ++i)  
                if (dist[mini][i])  
                     if (d[mini] + dist[mini][i] < d[i])  
                     {  
                          d[i] = d[mini] + dist[mini][i];  
                          prev[i] = mini;  
                     }  
      }  
 }  
 void main() {  
      int i, j;  
      int u, v, w;  
   //clrscr();  
      FILE *fin = fopen("dist.txt", "r");  
      fscanf(fin, "%d", &e);  
      for (i = 0; i < e; ++i)  
           for (j = 0; j < e; ++j)  
                dist[i][j] = 0;  
      n = -1;  
      for (i = 0; i < e; ++i) {  
           fscanf(fin, "%d%d%d", &u, &v, &w);  
           dist[u][v] = w;  
           n = MAX(u, MAX(v, n));  
      }  
      fclose(fin);  
      dijkstra(1);  
      printD();  
      printf("\n");  
      for (i = 1; i <= n; ++i) {  
           printf("Path to %d: ", i);  
           printPath(i);  
           printf("\n");  
      }  
      getch();  
 }  
 /*SAMPLE OUTPUT  
 ____________________  
 inputfile: dist.txt  
 10  
 1 2 10  
 1 4 5  
 2 3 1  
 2 4 3  
 3 5 6  
 4 2 2  
 4 3 9  
 4 5 2  
 5 1 7  
 5 3 4 
 _____________________  
 
 OUTPUT  
 Distances:  
 1  2  3  4  5  
 0  7  8  5  7  
 Path to 1: 1  
 Path to 2: 1 4 2  
 Path to 3: 1 4 2 3  
 Path to 4: 1 4  
 Path to 5: 1 4 5  
 */  

 

Distance Vector Routing Algorithm 

 //PROGRAM FOR DISTANCE VECTOR ROUTING ALGORITHM  
 #include<stdio.h>  
 #include<conio.h>  
 struct node  
 {  
   unsigned dist[20];  
   unsigned from[20];  
 }rt[10];  
 int main()  
 {  
   int dmat[20][20];  
   int n,i,j,k,count=0;  
   printf("\nEnter number of nodes : ");  
   scanf("%d",&n);  
   printf("\nEnter the cost matrix :\n");  
   for(i=0;i<n;i++)  
     for(j=0;j<n;j++)  
     {  
       scanf("%d",&dmat[i][j]);  
       dmat[i][i]=0;  
       rt[i].dist[j]=dmat[i][j];  
       rt[i].from[j]=j;  
     }  
   do  
   {  
     count=0;  
     for(i=0;i<n;i++)  
       for(j=0;j<n;j++)  
         for(k=0;k<n;k++)  
           if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])  
           {  
             rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];  
             rt[i].from[j]=k;  
             count++;  
           }  
   }while(count!=0);  
   for(i=0;i<n;i++)  
   {  
       printf("\n\nNODE %d ROUTING TABLE",i+1);  
       printf("\nNode\tDistance\tViaNode\n");  
       for(j=0;j<n;j++)  
       {  
         printf("\t\n %d\t  %d\t\t %d",j+1,rt[i].dist[j],rt[i].from[j]+1);  
       }  
   }  
   printf("\n\n");  
      return 0;  
   getch();  
 }    
 /*SAMPLE OUTPUT
**********INPUT*********
Enter number of nodes : 5
Enter the cost matrix :
0  4  2  6  99
4  0  99 99 99
2  99 0  3  99
6  99 3  0  2
99 99 99 2  0
 ::::::OUTPUT ::::: 
NODE 1 ROUTING TABLE  
 Node  Distance    ViaNode  
  1    0       1  
  2    4       2  
  3    2       3  
  4    5       3  
  5    7       4  
 NODE 2 ROUTING TABLE  
 Node  Distance    ViaNode  
  1    4       1  
  2    0       2  
  3    6       1  
  4    9       1  
  5    11      1  
 NODE 3 ROUTING TABLE  
 Node  Distance    ViaNode  
  1    2       1  
  2    6       1  
  3    0       3  
  4    3       4  
  5    5       4  
 NODE 4 ROUTING TABLE  
 Node  Distance    ViaNode  
  1    5       3  
  2    9       1  
  3    3       3  
  4    0       4  
  5    2       5  
 NODE 5 ROUTING TABLE  
 Node  Distance    ViaNode  
  1    7       4  
  2    11      4  
  3    5       4  
  4    2       4  
  5    0       5  

 

Cyclic Redundancy Check

=> A Generator is shared between the Sender and the Receiver.  
=> Sender will convert Dataword into Codeword using the Generator and send it 
 to the Receiver.  
=> Receiver upon receiving the Codeword, will check for errors in the received 
 Codeword with the help of the Generator. 
=> If no error is found, receiver can extract Dataword from the Codeword.  
 
Sender Side:

 Generator/Divisor: 1100000001011 (Total 13-bits)  
 Dataword: 10101 (5-bits)  
 Extended Dataword: 10101000000000000 (17-bits: Dataword + 12 0's)  
 
1100000001011 ) 10101000000000000 ( 11001  
                1100000001011  
                _____________  
                x1101000010110  
                 1100000001011  
                 _____________  
                 x0010000111010  
                  0000000000000  
                  _____________  
                  x0100001110100  
                   0000000000000  
                   _____________  
                   x1000011101000  
                    1100000001011  
                    _____________  
                    x100011100011  
 
=> So, CRC Bits are: 100011100011  
=> Now Codeword is 10101100001110100 (17-bits: Dataword + CRC bits)  
=> Sender will send this Codeword to the Receiver.  

 Receiver Side:  

 Codeword: 10101100011100011  
 Generator/Divisor: 1100000001011 
 
  1100000001011)   10101100011100011 ( 11001  
                  1100000001011  
                  _____________  
                  x1101100001010  
                   1100000001011  
                   _____________  
                   x0011000000010  
                    0000000000000  
                    _____________  
                    x0110000000101  
                     0000000000000  
                     _____________  
                     x1100000001011  
                      1100000001011  
                      _____________  
                      0000000000000  
 
 => Reached Codeword contain no errors and now extract Dataword from Codeword  
 => Dataword is 10101 [[by removing (Generator_Size - 1) bits from Codeword from Right]]  
 
 // PROGRAM FOR CYCLIC REDUNDANCY CHECK  
 #include<stdio.h>  
 int main()  
 {  
   int ds, dws, i, j, k, c=0; // ds-DivisorSize: dws-DataWordSize:  
   int div[100], dw[100], ta[100]; // div-Divisor: dw-DataWord: ta-TemporaryArray  
   //TAKING INPUT - DIVISOR  
   printf("Enter the size of divisor: ");  
   scanf("%d", &ds);  
   printf("Enter the divisor in bit pattern: ");  
   for(i=0; i<ds ; i++)  
     scanf("%d", &div[i]);  
   //TAKING INPUT - DATAWORD  
   printf("Enter the size of the DataWord: ");  
   scanf("%d",&dws);  
   printf("Enter the DATAWORD in bit pattern: ");  
   for(i=0; i<dws; i++)  
     scanf("%d",&dw[i]);  
   //ADDING ZEROS TO THE DATAWORD i.e., WE GOT EXTENDED DATAWORD HERE  
   for(i=dws; i<(dws+ds-1); i++)  
     dw[i] = 0;  
   //PRINTING THE EXTENDED DATAWORD  
   printf("Data after inserting zeros or <EXTENDED DATAWORD> : ");  
   for(i=0; i<(dws+ds-1); i++)  
     printf("%d", dw[i]);  
   //COPYING DATAWORD INTO TEMPORARY ARRAY  
   for(i=0; i<(dws+ds-1); i++)  
     ta[i] = dw[i];  
   //GENERATING THE REDUNDANT BITS  
   for(i=0; i!= dws; i++)  
   {  
     if(ta[i]==1)  
       for(j=0, k=i; j<ds; j++, k++)  
          ta[k] = ta[k]^div[j];   
   }  
   //ADDING REDUNDANT BITS TO THE DATAWORD  
   for(i=dws; i<(dws+ds-1); i++)  
     dw[i] = ta[i];  
   //PRINTING THE CODEWORD  
   printf("\n\nThe Generated CODEWORD is: ");  
   for(i=0; i<(dws+ds-1); i++)  
     printf("%d", dw[i]);  
   //COPYING CODEWORD INTO TEMPORARY ARRAY  
   for(i=0; i<(dws+ds-1); i++)  
     ta[i] = dw[i];  
   //DIVIDING CODEWORD WITH DIVISOR AT RECEIVERS END  
   for(i=0; i!= dws; i++)  
   {  
     if(ta[i]==1)  
       for(j=0, k=i; j<ds; j++, k++)  
         ta[k] = ta[k]^div[j];   
   }  
   printf("\nThe Remainder @ receiver's End is: ");  
   for(i=dws; i<(dws+ds-1); i++)  
       printf("%d",ta[i]);  
 //CHECKING IF THERE ARE ANY 1s IN THE REMAINDER  
   for(i=dws; i<(dws+ds-1); i++)  
   {  
     if(ta[i]!=0)  
       c++;  
   }  
   if(c==0)  
     printf("\nThe Codeword hasn't been altered::Message sent SUCCESSFULLY :)");  
   else  
     printf("\nThe Codeword has been altered :(");  
   return 0; 
 }  
 /* EXAMPLE OUTPUT  
 Enter the size of divisor: 4  
 Enter the divisor in bit pattern: 1 0 1 1  
 Enter the size of the DataWord: 5  
 Enter the DataWord in bit pattern: 1 0 1 1 1  
 Data after inserting zeros or <EXTENDED DATAWORD> : 10111000  
 The Generated CODEWORD is: 10111011  
 The Remainder @ receiver's End is: 000  
 The Codeword hasn't been altered::Message sent SUCCESSFULLY :)  
 */