Hi All,
Need help with my code. doesn't work at all it give me either no result & no error is showing i am using Borland C5
also this version is not working
how i can fix my code? where i can find Borland C5.5 Dolphi?====================
Here's my code
////// can somone help me with this?
//////
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void cc(char sen[]);
void main()
{
char sen[20];
int j,i,w=0;
printf(" enter the plaintext: ");
for(i=0;i<20;i++)
scanf("%s",sen[i]);
for(j=0;j<strlen(sen);j++)
if(sen[j]==' '|| sen[j]!=' ')
{ w++;
}
for(i=0;i<w;i++)
cc(sen);
getch();
}
void cc(char sen[])
{
FILE *fp ;
int i,j,k1[8],ls_2[10],k2[8],ls_1[10];
int p10[10],key[10] ;
int pt[8],IP[8],EP[8];
int a[4];
int b[8];
int c[8];
int temp[8];
char s[5];
int p[5],bin[8],div[8];
printf("Enter KEY= ");
for(i=0;i<10;i++)
scanf("%d",&key[i]);
p10[0]=key[2];
p10[1]=key[4];
p10[2]=key[1];
p10[3]=key[6];
p10[4]=key[3];
p10[5]=key[9];
p10[6]=key[0];
p10[7]=key[8];
p10[8]=key[7];
p10[9]=key[5];
ls_1[4]=p10[0];
for(j=0;j<4;j++)
ls_1[j]=p10[j+1];
ls_1[9]=p10[5];
for(j=5;j<9;j++)
ls_1[j]=p10[j+1];
k1[0]=ls_1[5];
k1[1]=ls_1[2];
k1[2]=ls_1[6];
k1[3]=ls_1[3];
k1[4]=ls_1[7];
k1[5]=ls_1[4];
k1[6]=ls_1[9];
k1[7]=ls_1[8];
ls_2[4]=ls_1[0];
ls_2[3]=ls_1[1];
for (j=0;j<3;j++)
ls_2[j]=ls_1[j+2];
ls_2[9]=ls_1[5];
ls_2[8]=ls_1[6];
for(j=5;j<8;j++)
ls_2[j]=ls_1[j+2];
k2[0]=ls_2[5];
k2[1]=ls_2[2];
k2[2]=ls_2[6];
k2[3]=ls_2[3];
k2[4]=ls_2[7];
k2[5]=ls_2[4];
k2[6]=ls_2[9];
k2[7]=ls_2[8];
printf("Enter plaintext= ");
for(i=0;i<20;i++)
s[i]=sen[i];
for(i=0;i<1;i++)
printf("\n ASCII= %d",s[i]);
for(i=0;i<1;i++)
p[i]=s[i];
int k[1];
div[0]=p[0]/2;
k[0]=p[0]%2;
for(i=0;i<8;)
{
if(div[i]>=0)
{
div[i+1]=div[i]/2;
bin[i+1]=div[i]%2;
}
else if(i==6)
bin[i+1]=0;
i++;
};
temp[0]=bin[7];
temp[1]=bin[6];
temp[2]=bin[5];
temp[3]=bin[4];
temp[4]=bin[3];
temp[5]=bin[2];
temp[6]=bin[1];
temp[7]=k[0];
for(i=0;i<8;i++)
pt[i]=temp[i];
IP[0]=pt[1];
IP[1]=pt[5];
IP[2]=pt[2];
IP[3]=pt[0];
IP[4]=pt[3];
IP[5]=pt[7];
IP[6]=pt[4];
IP[7]=pt[6];
for(i=0,j=4;i<4;i++,j++)
a[i]=IP[j];
EP[0]=a[3];
EP[1]=a[0];
EP[2]=a[1];
EP[3]=a[2];
EP[4]=a[1];
EP[5]=a[2];
EP[6]=a[3];
EP[7]=a[0];
for(i=0;i<8;i++)
b[i]=EP[i];
for(i=0;i<8;i++)
c[i]=b[i]^k1[i];
int s0[2],s1[2];
if((c[0]==0&&c[3]==0)&&(c[1]==0&&c[2]==0))
{ s0[0]=0;
s0[1]=1;
}
else if ((c[0]==0&&c[3]==1)&&(c[1]==0&&c[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((c[0]==0&&c[3]==0)&&(c[1]==0&&c[2]==1))
{ s0[0]=0;
s0[1]=0;
}
else if ((c[0]==0&&c[3]==1)&&(c[1]==0&&c[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((c[0]==0&&c[3]==0)&&(c[1]==1&&c[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((c[0]==0&&c[3]==0)&&(c[1]==1&&c[2]==1))
{ s0[0]=0;
s0[1]=1;
}
else if ((c[0]==0&&c[3]==0)&&(c[1]==1&&c[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((c[0]==0&&c[3]==1)&&(c[1]==1&&c[2]==1))
{ s0[0]=0;
s0[1]=0;
}
else if ((c[0]==1&&c[3]==0)&&(c[1]==0&&c[2]==0))
{ s0[0]=0;
s0[1]=0;
}
else if ((c[0]==1&&c[3]==1)&&(c[1]==0&&c[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((c[0]==1&&c[3]==0)&&(c[1]==0&&c[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((c[0]==1&&c[3]==1)&&(c[1]==0&&c[2]==1))
{ s0[0]=0;
s0[1]=1;
}
else if ((c[0]==1&&c[3]==0)&&(c[1]==1&&c[2]==0))
{ s0[0]=0;
s0[1]=1;
}
else if ((c[0]==1&&c[3]==1)&&(c[1]==1&&c[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((c[0]==1&&c[3]==0)&&(c[1]==1&&c[2]==1))
{ s0[0]=1;
s0[1]=1;
}
else if ((c[0]==1&&c[3]==1)&&(c[1]==1&&c[2]==1))
{ s0[0]=1;
s0[1]=0;
}
if((c[4]==0&&c[7]==0)&&(c[5]==0&&c[6]==0))
{ s1[0]=0;
s1[1]=0;
}
else if ((c[4]==0&&c[7]==1)&&(c[5]==0&&c[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((c[4]==0&&c[7]==0)&&(c[5]==0&&c[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((c[4]==0&&c[7]==1)&&(c[5]==0&&c[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((c[4]==0&&c[7]==0)&&(c[5]==1&&c[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((c[4]==0&&c[7]==0)&&(c[5]==1&&c[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((c[4]==0&&c[7]==0)&&(c[5]==1&&c[6]==1))
{ s1[0]=1;
s1[1]=1;
}
else if ((c[4]==0&&c[7]==1)&&(c[5]==1&&c[6]==1))
{ s1[0]=1;
s1[1]=1;
}
else if ((c[4]==1&&c[7]==0)&&(c[5]==0&&c[6]==0))
{ s1[0]=1;
s1[1]=1;
}
else if ((c[4]==1&&c[7]==1)&&(c[5]==0&&c[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((c[4]==1&&c[7]==0)&&(c[5]==0&&c[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((c[4]==1&&c[7]==1)&&(c[5]==0&&c[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((c[4]==1&&c[7]==0)&&(c[5]==1&&c[6]==0))
{ s1[0]=0;
s1[1]=1;
}
else if ((c[4]==1&&c[7]==1)&&(c[5]==1&&c[6]==0))
{ s1[0]=0;
s1[1]=0;
}
else if ((c[4]==1&&c[7]==0)&&(c[5]==1&&c[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((c[4]==1&&c[7]==1)&&(c[5]==1&&c[6]==1))
{ s1[0]=1;
s1[1]=1;
}
int t[4],x[4],P4[4];
t[0]=s0[0];
t[1]=s0[1];
t[2]=s1[0];
t[3]=s1[1];
P4[0]=t[1];
P4[1]=t[3];
P4[2]=t[2];
P4[3]=t[0];
for(i=0;i<4;i++)
x[i]=IP[i]^P4[i];
b[0]=x[3];
b[1]=x[0];
b[2]=x[1];
b[3]=x[2];
b[4]=x[1];
b[5]=x[2];
b[6]=x[3];
b[7]=x[0];
int y[8];
for(i=0;i<8;i++)
y[i]=b[i]^k2[i];
if((y[0]==0&&y[3]==0)&&(y[1]==0&&y[2]==0))
{ s0[0]=0;
s0[1]=1;
}
else if ((y[0]==0&&y[3]==1)&&(y[1]==0&&y[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((y[0]==0&&y[3]==0)&&(y[1]==0&&y[2]==1))
{ s0[0]=0;
s0[1]=0;
}
else if ((y[0]==0&&y[3]==1)&&(y[1]==0&&y[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((y[0]==0&&y[3]==0)&&(y[1]==1&&y[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((y[0]==0&&y[3]==0)&&(y[1]==1&&y[2]==1))
{ s0[0]=0;
s0[1]=1;
}
else if ((y[0]==0&&y[3]==0)&&(y[1]==1&&y[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((y[0]==0&&y[3]==1)&&(y[1]==1&&y[2]==1))
{ s0[0]=0;
s0[1]=0;
}
else if ((y[0]==1&&y[3]==0)&&(y[1]==0&&y[2]==0))
{ s0[0]=0;
s0[1]=0;
}
else if ((y[0]==1&&y[3]==1)&&(y[1]==0&&y[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((y[0]==1&&y[3]==0)&&(y[1]==0&&y[2]==1))
{ s0[0]=1;
s0[1]=0;
}
else if ((y[0]==1&&y[3]==1)&&(y[1]==0&&y[2]==1))
{ s0[0]=0;
s0[1]=1;
}
else if ((y[0]==1&&y[3]==0)&&(y[1]==1&&y[2]==0))
{ s0[0]=0;
s0[1]=1;
}
else if ((y[0]==1&&y[3]==1)&&(y[1]==1&&y[2]==0))
{ s0[0]=1;
s0[1]=1;
}
else if ((y[0]==1&&y[3]==0)&&(y[1]==1&&y[2]==1))
{ s0[0]=1;
s0[1]=1;
}
else if ((y[0]==1&&y[3]==1)&&(y[1]==1&&y[2]==1))
{ s0[0]=1;
s0[1]=0;
}
if((y[4]==0&&y[7]==0)&&(y[5]==0&&y[6]==0))
{ s1[0]=0;
s1[1]=0;
}
else if ((y[4]==0&&y[7]==1)&&(y[5]==0&&y[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((y[4]==0&&y[7]==0)&&(y[5]==0&&y[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((y[4]==0&&y[7]==1)&&(y[5]==0&&y[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((y[4]==0&&y[7]==0)&&(y[5]==1&&y[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((y[4]==0&&y[7]==0)&&(y[5]==1&&y[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((y[4]==0&&y[7]==0)&&(y[5]==1&&y[6]==1))
{ s1[0]=1;
s1[1]=1;
}
else if ((y[4]==0&&y[7]==1)&&(y[5]==1&&y[6]==1))
{ s1[0]=1;
s1[1]=1;
}
else if ((y[4]==1&&y[7]==0)&&(y[5]==0&&y[6]==0))
{ s1[0]=1;
s1[1]=1;
}
else if ((y[4]==1&&y[7]==1)&&(y[5]==0&&y[6]==0))
{ s1[0]=1;
s1[1]=0;
}
else if ((y[4]==1&&y[7]==0)&&(y[5]==0&&y[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((y[4]==1&&y[7]==1)&&(y[5]==0&&y[6]==1))
{ s1[0]=0;
s1[1]=1;
}
else if ((y[4]==1&&y[7]==0)&&(y[5]==1&&y[6]==0))
{ s1[0]=0;
s1[1]=1;
}
else if ((y[4]==1&&y[7]==1)&&(y[5]==1&&y[6]==0))
{ s1[0]=0;
s1[1]=0;
}
else if ((y[4]==1&&y[7]==0)&&(y[5]==1&&y[6]==1))
{ s1[0]=0;
s1[1]=0;
}
else if ((y[4]==1&&y[7]==1)&&(y[5]==1&&y[6]==1))
{ s1[0]=1;
s1[1]=1;
}
t[0]=s0[0];
t[1]=s0[1];
t[2]=s1[0];
t[3]=s1[1];
P4[0]=t[1];
P4[1]=t[3];
P4[2]=t[2];
P4[3]=t[0];
int z[4];
for(i=0,j=4;i<4;i++,j++)
z[i]=IP[j]^P4[i];
b[0]=z[0];
b[1]=z[1];
b[2]=z[2];
b[3]=z[3];
b[4]=x[0];
b[5]=x[1];
b[6]=x[2];
b[7]=x[3];
int IP_1[8];
IP_1[0]=b[3];
IP_1[1]=b[0];
IP_1[2]=b[2];
IP_1[3]=b[4];
IP_1[4]=b[6];
IP_1[5]=b[1];
IP_1[6]=b[7];
IP_1[7]=b[5];
int R[8],f;
j=0;
while(j<8)
{
if(j==0)
R[j]=IP_1[j]*1;
else if(j>0&&j<8)
switch(j)
{
case 1:R[j]=IP_1[j]*2;
break;
case 2:R[j]=IP_1[j]*2*2;
break;
case 3:R[j]=IP_1[j]*2*2*2;
break;
case 4:R[j]=IP_1[j]*2*2*2*2;
break;
case 5:R[j]=IP_1[j]*2*2*2*2*2;
break;
case 6:R[j]=IP_1[j]*2*2*2*2*2*2;
break;
case 7:R[j]=IP_1[j]*2*2*2*2*2*2*2;
break;
}
j++;
};
f=0;
for(i=0;i<8;i++)
f+=R[i];
printf("\n\n ASCII= ");
printf("%d ",f);
printf("\n\n The Ciphertext= ");
printf("%c",f);
if((fp = fopen("DES.txt", "w"))==NULL)
printf("file could not be opend");
else{
fprintf(fp," %c",f);
fclose(fp);
}
}