Смекни!
smekni.com

Программная реализация криптографического алгоритма шифрования с использованием открытого текста (стр. 3 из 3)

{'k','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j'},

{'l','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k'},

{'m','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l'},

{'n','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m'},

{'o','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n'},

{'p','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'},

{'q','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'},

{'r','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'},

{'s','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r'},

{'t','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s'},

{'u','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'},

{'v','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u'},

{'w','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v'},

{'x','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w'},

{'y','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'},

{'z','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'},};

while (1)

{printf("\nVvedite 1 dlya shifrovaniya \nVvedite 2 dlya rasshifrovaniya\nVvedite 3 dlya vihoda\n");

scanf("%d",&b);

switch (b)

{case 1: printf("%d - shifrovaniye\n",b);

printf("\nVibor regima:\n1 from klava\n2 from file\n");

scanf("%d",&f);

switch(f)

{case 1: printf("Vvedite slovo\n");

cin>>x1;

printf("\nVvedite kluchevoy simvol\n");

cin>>x2;

for ( z2=strlen(x1)-1;z2>0;z2--)

{x3[z2]=x1[z2-1];}

x3[0]=x2;

x3[strlen(x1)]='\0';

printf("\nSlovo dlya shifrovaniya: %s\n",x1);

printf("\nKluchevoy simvol: %c\n",x2);

printf("\nKluchevaiya posledovatel'nost': %s\n",x3);

int z3;

for (z3=0;z3<20;z3++)

{z1 = y1 = 0;

if((x1[z3] !='&bsol;0')||(x3[z3] !='&bsol;0'))

{for (z2=0;z2<27;z2++)

if (alfavit[0][z2]==x1[z3])

{z1=z2;

break;}

for (y=0;y<27;y++)

if (alfavit[y][0]==x3[z3])

{y1=y;

break;}

x5[z3]=alfavit[y1][z1];}

else

break;}

x5[z3] = '&bsol;0';

printf("&bsol;nShifrotekst: %s&bsol;n",x5);

break;

case 2: puts("Put name of file with open text:&bsol;n");

scanf("%s",&filename);

text=fopen(filename,"r");

while(!(feof(text)))

{c=getc(text);

r++;}

fseek(text,0,0);

i=0;

while(r!=1)

{c=getc(text);

x1[i]=c;

r--;

i++;}

printf("&bsol;nVvedite kluchevoy simvol&bsol;n");

cin>>x2;

for ( z2=strlen(x1)-1;z2>0;z2--)

{x3[z2]=x1[z2-1];}

x3[0]=x2;

x3[strlen(x1)]='&bsol;0';

printf("&bsol;nSlovo dlya shifrovaniya: %s&bsol;n",x1);

printf("&bsol;nKluchevoy simvol: %c&bsol;n",x2);

printf("&bsol;nKluchevaiya posledovatel'nost': %s&bsol;n",x3);

for (z3=0;z3<20;z3++)

{z1 = y1 = 0;

if((x1[z3] !='&bsol;0')||(x3[z3] !='&bsol;0'))

{for (z2=0;z2<27;z2++)

if (alfavit[0][z2]==x1[z3])

{z1=z2;

break;}

for (y=0;y<27;y++)

if (alfavit[y][0]==x3[z3])

{y1=y;

break;}

x5[z3]=alfavit[y1][z1];}

else

break;}

x5[z3] = '&bsol;0';

printf("&bsol;nShifrotekst: %s&bsol;n",x5);

fclose(text);

break;

default: return;}

break;

case 2: printf("%d - rasshifrovaniye&bsol;n",b);

printf("&bsol;nVibor regima:&bsol;n1 from klava&bsol;n2 from file&bsol;n");

scanf("%d",&f);

switch(f)

{case 1:printf("&bsol;nVvedite shifrotekst:&bsol;n");

cin>>t1;

printf("&bsol;nVvedite kluchevoy simvol:&bsol;n");

cin>>t2;

printf("&bsol;nShifrotekst: %s&bsol;n",t1);

printf("&bsol;nKluchevoy simvol: %c&bsol;n", t2);

int i2;

for (i2=0;t1[i2];i2++)

{i1 = j1 = 0;

{for (i=0;i<32;i++)

if (alfavit[i][0]==t2)

{i1=i;

break;}

for (j=0;j<34;j++)

if (alfavit[i1][j]==t1[i2])

{j1=j;

break;}

t5[i2]=alfavit[0][j1];}

t2=t5[i2];}

t5[i2] = '&bsol;0';

printf("&bsol;nOtkritiy tekst: %s&bsol;n",t5);

break;

case 2:puts("Put name of file with open text:&bsol;n");

scanf("%s",&filename);

text=fopen(filename,"r");

while(!(feof(text)))

{c=getc(text);

r++;}

fseek(text,0,0);

i=0;

while(r!=1)

{c=getc(text);

t1[i]=c;

r--;

i++;}

printf("&bsol;nVvedite kluchevoy simvol:&bsol;n");

cin>>t2;

printf("&bsol;nShifrotekst: %s&bsol;n",t1);

printf("&bsol;nKluchevoy simvol: %c&bsol;n", t2);

for (i2=0;t1[i2];i2++)

{i1 = j1 = 0;

{for (i=0;i<32;i++)

if (alfavit[i][0]==t2)

{i1=i;

break;}

for (j=0;j<34;j++)

if (alfavit[i1][j]==t1[i2])

{j1=j;

break;}

t5[i2]=alfavit[0][j1];}

t2=t5[i2];}

t5[i2] = '&bsol;0';

printf("&bsol;nOtkritiy tekst: %s&bsol;n",t5);

fclose(text);}

break;

case 3: return;

default: printf("%d - tolko 1 ili 2!!!&bsol;n",b);

return;}}}