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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| #include <stdio.h>
#include <stdlib.h>
#include "uea2.h"
#include "uia2.h"
#define SIZE 16
#define enc 1 //0 pour la 2eme methode qui est la methode d'integrite ,
//1 pour la 1er methode , methode de confidentialite
int main(int argc, char** argv)
{
u8 *k,*data;
int i,dir,encLen,count,j,length;
char *s="Test phrase,cryptage,....";
char *c=*s;
#if (enc == 1)
//ici on fait generation de confidentialite mode a partir du DATA
int bearer;
k = malloc(SIZE);//ici le k est un tableu de 16 elements , et chaque elements de 8 bits.
length=strlen(s);
encLen = length*8;//on convertit le length au bits :) :)
data = malloc(length);//ici le data est un tableu de 20 elements , et chaque elements de 8 bits.
//ici ce sont les key d'initialisation qui sont les ciphers key sur 32 bits chaqun
k[0]=100;
k[1]=23;
k[2]=65;
k[3]=210;
k[4]=55;
k[5]=115;
k[6]=50;
k[7]=255;
k[8]=8;
k[9]=179;
k[10]=220;
k[11]=233;
k[12]=25;
k[13]=140;
k[14]=109;
k[15]=20;
bearer=300;
count=10;
dir=150;
printf("Cas du chiffrement de confidentialite \n La Phrase a chiffree est: \n");
for(j=0;j<strlen(s);j++)
printf("%c",(char)s[j]);
//printf("\n La longueur du phrase est=%d caracteres \n \n Les Codes ASCII du phrase originale est: \n ",length);
printf("\n \n");
for(j=0;j<length;j++)
{
data[j]=s[j];
printf("%d ",data[j]);
}
printf("\n \n");
uea2(k,count,bearer,dir,data,encLen,1);//la longueur du key genere est 4*(encLen+31)/32;
printf("\n\n");
printf("La phrase chiffree est: \n");
for(j=0;j<strlen(data);j++)
printf("%c",(char)data[j]);
printf("\n \n");
//je veux ici applique de nouveau le meme algorithme et voir si donne la reponse originale
printf("\n Applique un 2eme fois pour le decryptage \n");
uea2(k,count,bearer,dir,data,encLen,0);
printf("Le code ASCII du phrase est:\n");
for(j=0;j<strlen(s);j++)
{
printf("%d ",data[j]);
//printf("%c \n",(char)data[j]);
//fprintf(fp,"%d ",data[j]);
}
printf("\n \n");
for(j=0;j<strlen(s);j++)
printf("%c",(char)data[j]);
scanf("%d",&i);
#else
//ici on fait generation d'intergrite mode a partir du DATA
int fresh;
u8* mac;
u64 macLen;
k = malloc(SIZE);//ici le k est un tableu de 16 elements , et chaque elements de 8 bits.
length=strlen(s);
encLen = length*8;
data = malloc(length);
k[0]=100;
k[1]=23;
k[2]=65;
k[3]=210;
k[4]=55;
k[5]=115;
k[6]=50;
k[7]=255;
k[8]=8;
k[9]=179;
k[10]=220;
k[11]=233;
k[12]=25;
k[13]=140;
k[14]=109;
k[15]=20;
count=10;
dir=150;
fresh=20;
macLen = encLen;
printf("\n Cas du chiffrement d'integrite \n La Phrase a chiffree est: \n");
for(j=0;j<strlen(s);j++)
printf("%c",(char)s[j]);
printf("\n \n La longueur du phrase est=%d caracteres \n \n Les Codes ASCII du phrase originale est: \n ",length);
for(j=0;j<length;j++)
{
data[j]=s[j];
printf("%d ",data[j]);
}
printf("\n \n");
mac = uia2(k,count,fresh,dir,data,macLen);
printf("\n La longueur du phrase crypte est=%d caracteres \n \n Les Codes ASCII du phrase cryptee est: \n ",strlen(mac));
for(i=0;i<strlen(mac);i++)
printf("%d ",mac[i]);
printf("\n \n ");
for(i=0;i<strlen(mac);i++)
printf("%c",(char)(mac[i]));
//2eme fois
//mac = uia2(k,count,fresh,dir,mac,macLen);
//for(i=0;i<strlen(mac);i++)
// printf("%d ",mac[i]);
//printf("\n \n ");
//for(i=0;i<strlen(mac);i++)
//printf("%c",(char)(mac[i]));
scanf("%d",&i);
#endif
} |
Partager