You are on page 1of 6

Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

PRÁCTICA 1: Ataque de sólo texto cifrado

Escuela Superior de Cómputo

Resumen
En esta práctica aplicamos el ataque de texto cifrado sobre tres documentos.
Básicamente analizamos el texto y realizamos varios intentos a partir de diversas
hipótesis para encontrar el texto plano.

Palabras clave: Ataque de texto cifrado, cripto análisis.

1. Introducción
Existen diferentes modelos de ataque. De cierta forma el modelo de ataque viene
determinado por la información disponible para el atacante que inicia el ataque al crip-
tosistema. El ataque de “sólo texto cifrado” (ciphertext only attack en inglés) es aquel
en el que el atacante posee una cadena de texto cifrado. Usualmente puede haber otro
tipo de ayudas como es el caso de saber en qué idioma está el texto plano, o el hecho
de que los espacios y los signos de puntuación no estén cifrados.

Incluso puede ser de ayuda contar con una tabla que muestre las probabilidades de
ocurrencia de cada letra en un idioma dado ya que esto ayuda a poder descifrar la llave
que se utilizó para cifrar el texto.

2. Intentos para descifrar el texto


Para los dos primeros archivos de texto cifrado c1 edsger.txt, c2 edsger.txt la
estrategia fue probar si habı́a un corrimiento en los caracteres. Es decir, un corrimiento
de +1 de un carácter ASCII significarı́a que en lugar de la letra a estarı́a una letra b,
mientras que un corrimiento negativo (por ejemplo de −2 significarı́a que en lugar de
una c está una a y ası́ sucesivamente.

Está hipótesis surgió del hecho de que el texto cifrado parecı́a estar bien diferencia-
do en palabras de longitud normal, e incluso con algunos signos de puntuación. Para
probar la hipótesis implementamos el siguiente ciclo sobre un fragmento de cada uno

1
Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

de los dos textos antes mencionados.

1 f o r ( i =−20; i <20; i ++)


2 {
3 f o r ( j =0; j <200; j ++)
4 {
5 nueva [ j ] = o r i g i n a l [ j ]+ i ;
6 p r i n t f ( ” %d : %s \n” , i , nueva ) ;
7 }
8 }

Observando en la terminal las distintas salidas para diferentes valores de corrimiento


en la codificación ASCII pudimos determinar cuál era el número que correspondı́a a
cada texto cifrado. También observando la salida pudimos concluir que la regla de
recorrer el carácter no se aplicaba a las mayúsculas ni a los signos de puntuación lo que
llevó a la implementación de la función que se muestra en la siguiente sección.

3. Funciones implementadas
La siguiente es la función decrypt 1() que recibe como parámetros el número de
caracteres en el texto cifrado, y los apuntadores a dos archivos: el texto cifrado y un
archivo nuevo donde se guardará el texto plano descifrado.

Podremos observar que en la lı́nea 8 se toma cada carácter del archivo original de-
nominado aquı́ encriptado para procesarlo. La condición en la lı́nea 9 es para hacer el
cambio respectivo si el carácter leı́do es una letra minúscula. De lo contrario el nuevo
carácter será el mismo que el original

Si el carácter leı́do es una letra minúscula se procede a restarle 7 a su valor en la


codificación ASCII, excepto si es un carácter antes de la letra ‘h’ ya que en ese caso
al restar el número 7 nos saldrı́amos de los valores que ASCII le asigna a las letras
del alfabeto y lo intercambiarı́a por otro tipo de sı́mbolo. Por ello se considera que el
alfabeto está en una cola circular, y no sólo se restarán 7 sino además se sumarán 26
lugares para considerar a las últimas letras del alfabeto.

1 void d e c r y p t 1 ( int tam , FILE ∗ e n c r i p t a d o , FILE ∗ d e s c i f r a d o )


2 {
3 char o r i g i n a l ;
4 char nuevo ;
5 int j ;
6 f o r ( j = 0 ; j < tam ; j ++)
7 {
8 o r i g i n a l = fgetc ( encriptado ) ;
9 i f ( i s a l p h a ( o r i g i n a l ) && i s l o w e r ( o r i g i n a l ) )
10 /∗ S ó l o s e cambiarán l e t r a s m i n ú s c u l a s ∗/
11 {
12 i f ( original <’h ’ )

2
Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

13 /∗ Caso e s p e c i a l para l o s c a r a c t e r e s a n t e s de l a ’ h ’ ∗/
14 {
15 nuevo = o r i g i n a l −7+26;
16 }
17 else
18 {
19 nuevo = o r i g i n a l −7;
20 }
21 }
22 e l s e nuevo = o r i g i n a l ;
23 f p u t c ( nuevo , d e s c i f r a d o ) ;
24 }
25 }

Para el segundo texto cifrado se utilizó una función prácticamente idéntica , con la
única salvedad de que en este caso cada carácter ASCII está recorrido dos posiciones
hacia delante. A continuación mostramos el código de la función.

1 void d e c r y p t 2 ( int tam , FILE ∗ e n c r i p t a d o , FILE ∗ d e s c i f r a d o )


2 {
3 char o r i g i n a l ;
4 char nuevo ;
5 int j ;
6 f o r ( j = 0 ; j < tam ; j ++)
7 {
8 o r i g i n a l = fgetc ( encriptado ) ;
9 i f ( i s a l p h a ( o r i g i n a l ) && i s l o w e r ( o r i g i n a l ) )
10 {
11 i f ( o r i g i n a l >= ’ y ’ )
12 {
13 nuevo = o r i g i n a l +2−26;
14 }
15 else
16 {
17 nuevo = o r i g i n a l +2;
18 }
19 }
20 e l s e nuevo = o r i g i n a l ;
21 f p u t c ( nuevo , d e s c i f r a d o ) ;
22 }
23 }

Para el ultimo texto cifrado hubo algunas diferencias. Por su apariencia no era un
cambio entre letras pues en su mayorı́a aparecı́an números y caracteres especiales. Exa-
minando la tabla del código ASCII pudimos observar que tales sı́mbolos eran un mapeo
entre la columna de sı́mbolos especiales y la de las letras minúsculas. Por lo tanto apli-
camos una técnica similar sumando 64 al código ASCII de cada sı́mbolo.

Sin embargo algunos sı́mbolos de puntuación no debı́an cambiarse y otros sı́. Allı́ fue
donde tuvimos problemas pues no supimos como identificar alguna secuencia de esca-
pe para distinguir los sı́mbolos que debı́an cambiarse de los que no. A continuación

3
Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

mostramos la función decrypt 3() que utilizamos para este último caso.
1 void d e c r y p t 3 ( int tam , FILE ∗ e n c r i p t a d o , FILE ∗ d e s c i f r a d o )
2 {
3 char o r i g i n a l ;
4 char nuevo ;
5 int j ;
6 /∗ Realizamos l a l e c t u r a d e l a r c h i v o tam v e c e s ∗/
7 f o r ( j = 0 ; j < tam ; j ++)
8 {
9 o r i g i n a l = fgetc ( encriptado ) ;
10 i f ( o r i g i n a l != ’ ’ && o r i g i n a l != ’ \n ’ && o r i g i n a l != ’ ? ’ && ! i s u p p e r ( o r i g i n a l ) )
11 {
12 nuevo = o r i g i n a l + 6 4 ;
13 }
14 e l s e nuevo = o r i g i n a l ;
15 f p u t c ( nuevo , d e s c i f r a d o ) ;
16 }
17 }

4. Texto plano obtenido


Texto plano del archivo c1 edsger.txt:

Since a number of years I am familiar with the observation that the quality of
programmers is a decreasing function of the density of go to statements in the
programs they produce. Later I discovered why the use of the go to statement has
such disastrous effects and did I become convinced that the go to statement should
be abolished from all “higher level”programming languages (i.e. everything except
−perhaps− plain machine code). At that time I did not attach too much impor-
tance to this discovery; I now submit my considerations for publication because
in very recent discussions in which the subject turned up, I have been urged to do so.

My first remark is that, although the programmer’s activity ends when he has cons-
tructed a correct program, the process taking place under control of his program is
the true subject matter of his activity, for it is this process that has to effectuate
the desired effect, it is this process that in its dynamic behaviour has to satisfy the
desired specifications. Yet, once the program has been made, the “making” of the
corresponding process is delegated to the machine.

Texto plano del archivo c2 edsger.txt:

4
Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

After having programmed for some three years, I had a discussion with A. van
Wijngaarden, who was then my boss at the Mathematical Centre in Amsterdam,
a discussion for which I shall remain grateful to him as long as I live. The point
was that I was supposed to study theoretical physics at the University of Leiden
simultaneously, and as I found the two activities harder and harder to combine, I
had to make up my mind, either to stop programming and become a real, respectable
theoretical physicist, or to carry my study of physics to a formal completion only,
with a minimum of effort, and to become....., yes what? A programmer? But was
that a respectable profession? For after all, what was programming? Where was
the sound body of knowledge that could support it as an intellectually respectable
discipline? I remember quite vividly how I envied my hardware colleagues, who,
when asked about their professional competence, could at least point out that they
knew everything about vacuum tubes, amplifiers and the rest, whereas I felt that,
when faced with that question, I would stand empty-handed. Full of misgivings I
knocked on van Wijngaarden’s office door, asking him whether I could “speak to
him for a moment”; when I left his office a number of hours later, I was another
person. For after having listened to my problems patiently, he agreed that up till
that moment there was not much of a programming discipline, but then he went on
to explain quietly that automatic computers were here to stay, that we were just at
the beginning and could not I be one of the persons called to make programming
a respectable discipline in the years to come? This was a turning point in my life
and I completed my study of physics formally as quickly as I could. One moral of
the above story is, of course, that we must be very careful when we give advice to
younger people; sometimes they follow it!

Texto plano obtenido (mejorable) del archivo c3 edsger.txt:

5
Cryptography, Sem: 2018-1, 3CV2, Práctica 1, 15 de agosto de 2017

Before airing a number of comments and remarks I would like to tell you something
about my past lest I be misunderstoodn
Firstly mmand this is apparently in contrast to a number of people presentmm I
consider myself a lucky person because I am perfectly happy with the role that
mathematics have played in my lifen Extended over a period of tu yearsl my mat-
hematical education has beenl I guessl about a qp man year effort { you may not
like the resultl but I liked most of the experience immensely and that amount of fun
and intellectual excitement I regardl all by itselfl as a sufficient justificationn Besides
thatl my enjoyment was untampered by the now fashionable quibble about bhere-
dityb versus benvironmentbl because in any case my dear mother played a major
role in itn
Why do I bring this up? Welll simplyl because the only fruitful way of considering
computersl that I know ofl is regarding them as mathematical machinesn Knowing
thatl I came to this symposium with very low expectationsl because this yeargs mot-
to is bComputers and the educated individualbn But mathematicsl howeverl are no
longer regarded as an essential ingredient of the cultural baggage of the educated
mana Read Eric Temple Bell complaining about the watering down of the Ameri-
can high schooll where mediocrity has become the norml a degradation covered by
a misuse of the notion bdemocraticbn Read Courantgs introduction to Morris Kli-
negs bMathematics and the Western Culturebl and look around yourselfz you will
find many in your environment who pose as educated persons and simultaneously
announce with some curious pride that bof course they never understood mathe-
maticsbn Two generations agol the pitiful one who found mathematics beyond himl
tried to cover up his mental infirmityn In shortz with todaygs beducatedb individuall
and with computers being mathematical machinesl our subject bComputers and the
educated individualb has a hard time in finding an area of applicationn
To make things worsel the beducated individualb is so unfashionable as to have be-
come nearly extinctn In the name of justice and equalityl the bright pupils are no
longer allowed to understand what the stupid ones cannot graspl and many a go-
vernment threatens the race of the wellmeducated individuals with genociden In the
hands of the pedagogues education has been replaced by trainingl what used to be
sowing the seeds of understanding with a hope for harvest has been replaced by edu-
cational engineeringn Even the individual had better disappear and submerge into a
team as quickly as possiblen Instead of bComputers and the educated individualbl
I propose the more appropriate titlez bComputers and the illmtrained mobbn

5. Referencias
D. R. Stinson. “Classical Cryptography” en Cryptography Theory and Practice, 3rd
edition, Ed. Ontario: Chapman & Hall/CRC, 2006, pp. 26-28.

You might also like