-
-
Save ErikRamses/5973215 to your computer and use it in GitHub Desktop.
Descripción del algoritmo de cifrado de flujo A5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Codigo obtenido de la siguiente URL: http://delta.cs.cinvestav.mx/~francisco/arith/Flujo.pdf | |
void a5_key(a5_ctx *c, char *k) //Funcion donde se definen las longitudes de los registros | |
{ | |
c->r1 = k[0]<<11|k[1]<<3 | k[2]>>5; /* 19 */ | |
c->r2 = k[2]<<17|k[3]<<9 | k[4]<<1 | k[5]>>7; /* 22 */ | |
c->r3 = k[5]<<15|k[6]<<8 | k[7]; /* 23 */ | |
} | |
int a5_step(a5_ctx *c) //Funcion donde se obtiene el valor de las variables de control de tiempo | |
{ | |
int control; | |
control = threshold(c->r1,c->r2,c->r3); | |
c->r1 = clock_r1(control,c->r1); | |
c->r2 = clock_r2(control,c->r2); | |
c->r3 = clock_r3(control,c->r3); | |
return((c->r1^c->r2^c->r3)&1); | |
} | |
/* cifra un bufer de longitud len */ | |
void a5_encrypt(a5_ctx *c, char *data, int len) //Funcion de encriptacion | |
{ | |
int i,j; | |
char t; | |
for(i=0;i<len;i++) | |
{ | |
for(j=0;j<8;j++) | |
t = t << 1 | a5_step(c); | |
data[i]^=t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment