-
Notifications
You must be signed in to change notification settings - Fork 1
/
cesarDecrypt.c
46 lines (35 loc) · 998 Bytes
/
cesarDecrypt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ===========================================================================
* Autor: Lara Revilla y Sergio Alonso (rscx31)
* Uso: FunciÃon externa al programa de seguridad. Se usa en lfuncion4.c
* Funcion: Decodifica una cadena previamente cifrada con codigo cesar.
* Plataforma: Compilado y probado en Linux 2.6.26, 2.6.32 y 2.6.35
* Fecha: 15-10-10
* ===========================================================================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* cesarDecrypt(char cadena[],int pos, char codigocesar[])
{
int i,j,longitud_cad,dif;
char abecedario[26];
sprintf(abecedario, "abcdefghijklmnopqrstuvwxyz");
longitud_cad=strlen(cadena);
for (i=0; i<=longitud_cad; i++)
{
for(j=0; j<=25; j++)
{
if (cadena[i]==abecedario[j])
{
if(j+1<=pos)
{
dif=25-(pos-(j+1));
codigocesar[i]=abecedario[dif];
} else {
codigocesar[i]=abecedario[j-pos];
}
}
}
}
return(codigocesar);
}