Sie sind auf Seite 1von 12

INSTITUTO POLITÉCNICO NACIONAL

ESCUELA SUPERIOR DE CÓMPUTO

Cryptography

“IP & IP^-1”

Abstract

In this practice you must have an entry text where a permutation will be made so that the text
can be manipulated as an entry permutation. The reverse way is the same way, which the input
text is the text after the input permutation, and then an inverse permutation will be
performed, and the output will be the original input.

By:

Rodríguez García Adán Iván

Professor:
MSc. NIDIA ASUNCIÓN CORTEZ DUARTE

October 2019
Index

Contenido
Introduction:................................................................................................................1

Literature review:.........................................................................................................1

Software (libraries, packages, tools):..............................................................................1

Procedure:...................................................................................................................2

Results.........................................................................................................................3

Discussion:..................................................................................................................3

Conclusions:................................................................................................................5

References:..................................................................................................................5

Code............................................................................................................................6

i
Introduction:

The at the beginning of the DES algorithm, the text that will be cipher need to have the
value in hexadecimal. Then the text will permute with the choice 1 and the result will use for do the
operations of cipher the text.

This text are a matrix of 56 bites and will separated in two blocks Lo and Ro. The inverse
permutated is the same steps but with the permutated

Literature review:

The method used when encrypting and decrypting is the [1] DES that was developed by
IBM, the implementations of DES published so far are based on the straightforward application of
the NIST standard. This article describes an innovative architecture that features a speed increase
for both hardware and software implementations, compared to the state of the art.

Software (libraries, packages, tools):

The program was created in c , this is an advantage, because the program works in the low level
and the bits are more easy to manipulate with the logic operations and the easily to show binaries to
hexadecimal.

The materials that used in this practice was:

1. Shell on Linux

1
Procedure:

Figure 2. Flow chart

In the flowchart, it is observed that the input word needs to be in binary, it is necessary to
know that its module and the rest of each letter and a path will be made on the left side depending
on the bits of the module.

Finally, the result is saved in an arrangement where it should only be converted to become
hexadecimal.

2
Results

3
4
5
6
Discussion:

When performing Table 2 with the comparison of each type of encryption, it can be seen
that they are more effective in some types of images than in others. as it is in Figure 3.1 and Figure
3.2 where the JAPAN flag still stands out from the encrypted background, so that another image
encrypted with the same type, cannot be distinguished. The other types of encryption with the AES
method, both the flower and the flag of Japan, have the same characteristic not to be recognizable.

Conclusions:

The algorithm DES it is necessary to know that its module and the rest of each letter and a
path will be made on the left side depending on the bits of the module. This is an characteristic that
will be used for work with the binaries, and the mode that handler the bytes. This algorithm is very
useful because is necessary to have the matrix of permutation and the inverse matrix, that was use
for all the process of cipher.

References:

[1] FIPS, “Data Encryption Standard”, Federal Information Processing Standards Publication 46-2,
1993 December 30.

[2] Wilcox, D.C., et al., “A DES ASIC suitable for network encryption at 10Gbps and beyond”,
First International Workshop on Cryptographic Hardware and Embedded Systems, 1999.

7
Code

1. #include <stdio.h>  
2. #include<string.h>  
3.   
4. void PrintResult(unsigned int array[]);  
5.   
6. int main(){  
7.     //Palabra original  
8.     unsigned char m[]={'D','i','a','m','a','n','t','e'};//8 bytes  
9.     unsigned char minv[]={0xff,0x40,0xe9,0x9e,0x00,0xfe,0x2a,0x20};//8 bytes   
10.     //Matriz de permutaci�n  
11.     unsigned char matrix[]={58,50,42,34,26,18,10,2,  
12.                             60,52,44,36,28,20,12,4,   
13.                             62,54,46,38,30,22,14,6,  
14.                             64,56,48,40,32,24,16,8,  
15.                             57,49,41,33,25,17,9,1,  
16.                             59,51,43,35,27,19,11,3,  
17.                             61,53,45,37,29,21,13,5,  
18.                             63,55,47,39,31,23,15,7};//64 bytes            
19.     unsigned char matrixinv[]={40,8,48,16,56,24,64,32,  
20.                                39,7,47,15,55,23,63,31,   
21.                                38,6,46,14,54,22,62,30,  
22.                                37,5,45,13,53,21,61,29,  
23.                                36,4,44,12,52,20,60,28,  
24.                                35,3,43,11,51,19,59,27,  
25.                                34,2,42,10,50,18,58,26,  
26.                                33,1,41,9,49,17,57,25};//64 bytes  
27.     //Contadores y contenedores  
28.     unsigned char i=0,num=0 /*,res=0,mod=0,rec=0*/;//1 byte c/u (2 total)  
29.     //Arreglo donde va la cadena permutada, sin representaci�n  
30.     unsigned char temp[64]={0};//64 bytes  
31.     //Arreglo para impresi�n hexadecimal  
32.     unsigned int initialperm[16]={0};//64 bytes  
33.     //Arreglo para impresi�n hexadecimal  
34.     unsigned int initialperminv[16]={0};//64 bytes  
35.     //Impresi�n de diamante en hexadecimal  
36.     printf("Diamante = 0x");  
37.     for(i;i<8;i++){printf(" %x", m[i]);}  
38.     printf("\n");  
39.     i=0;  
40.     //Impresi�n de la permutaci�n  
41.     printf("Permutacion\n");  
42.     printf("--------------------\n");  
43.     for(i;i<64;i++){//32  
44.         if(matrix[i]%8==0){  
45.             temp[i] = !!((m[(matrix[i]/8)-1] << (7)) & 0x80);   
46.         }else{  
47.             temp[i] = !!((m[matrix[i]/8] << ((matrix[i]%8)-1)) & 0x80);  
48.         }  
49.         //temp[i]=rec;                
50.         printf("%d", temp[i]);  
51.         if(i%8==3)printf("-");  
52.         if(i%8==7)printf("\n");  
53.     }  
54.     printf("--------------------\n");  
55.     /////////////////////////////////////////////////////////////////////  
56.     ///////////////"Conversi�n" en d�gitos de 4 bits para su posterior   
57.     //////////////representaci�n en hexadecimal  
58.     /////////////////////////////////////////////////////////////////////  

8
59.     i=4;  
60.     for(i;i<65;i+=4){//Se ejecuta 16 veces  
61.         initialperm[num]=((int)temp[i-4])*1000+((int)temp[i-3])*100+((int)temp[i-
2])*10+((int)temp[i-1]);  
62.         num++;  
63.     }  
64.     //print the permutation   
65.     printf("IP(Diamante)= 0x ");  
66.     PrintResult(initialperm);  
67.     printf("\n");  
68.       
69.     i=0;  
70.     printf("IP(IP-1)\n");  
71.     printf("--------------------\n");  
72.     /////////////////////////////////////////////////////////////////////  
73.     ///////////////Read the bytes for every letter and only   
74.     //////////////  
75.     /////////////////////////////////////////////////////////////////////  
76.     for(i;i<64;i++){//32  
77.         if(matrixinv[i]%8==0){  
78.             temp[i] = !!((minv[(matrixinv[i]/8)-1] << (7)) & 0x80);     
79.         }else{  
80.             temp[i] = !!((minv[matrixinv[i]/8] << ((matrixinv[i]%8)-1)) & 0x80);  
81.         }  
82.         //temp[i]=rec;                
83.         printf("%d", temp[i]);  
84.         if(i%8==3)printf("-");  
85.         if(i%8==7)printf("\n");  
86.     }  
87.     printf("--------------------\n");  
88.     /////////////////////////////////////////////////////////////////////  
89.     ///////////////"Conversi�n" en d�gitos de 4 bits para su posterior   
90.     //////////////representaci�n en hexadecimal  
91.     /////////////////////////////////////////////////////////////////////  
92.     i=4;  
93.     num=0;  
94.     for(i;i<65;i+=4){//Se ejecuta 16 veces  
95.         initialperminv[num]=((int)temp[i-4])*1000+((int)temp[i-3])*100+
((int)temp[i-2])*10+((int)temp[i-1]);  
96.         num++;  
97.     }  
98.     printf("IP(IP-1)= 0x ");  
99.     PrintResult(initialperminv);  
100.     printf("\n");  
101.     return 0;     
102. }  
103.     /////////////////////////////////////////////////////////////////////  
104.     ///////////////Representation of the base depending  
105.     //////////////the base that was used  
106.     /////////////////////////////////////////////////////////////////////  
107. void PrintResult(unsigned int array[]){  
108.     unsigned char i=0;  
109.     for(i;i<16;i++){  
110.         if(array[i]==0){printf("0");  
111.         }else if(array[i]==1){printf("1");  
112.         }else if(array[i]==10){printf("2");  
113.         }else if(array[i]==11){printf("3");  
114.         }else if(array[i]==100){printf("4");  
115.         }else if(array[i]==101){printf("5");  
116.         }else if(array[i]==110){printf("6");  
117.         }else if(array[i]==111){printf("7");  

9
118.         }else if(array[i]==1000){printf("8");  
119.         }else if(array[i]==1001){printf("9");  
120.         }else if(array[i]==1010){printf("a");  
121.         }else if(array[i]==1011){printf("b");  
122.         }else if(array[i]==1100){printf("c");  
123.         }else if(array[i]==1101){printf("d");  
124.         }else if(array[i]==1110){printf("e");  
125.         }else if(array[i]==1111){printf("f");  
126.         }  
127.         if(i%2==1)printf(" ");  
128.     }  
129.     printf("\n");     
130. }

10

Das könnte Ihnen auch gefallen