首条民营资本控股高铁:高手帮忙些个c程序

来源:百度文库 编辑:高校问答 时间:2024/04/29 21:17:26
请问这个程序谁会写?帮帮忙~~~~~急
密码是一个数字串,例如,以下是两条密码:
第一条:7.21, 7, 17, 6.7.1,13, 19, 10, 2.18, 25, 9, 3.25, 18, 16, 7, 14.18, 13.18, 6, 3.11, 13, 13, 12, -2
第二条:12, 20.8, 23, 16, 1, 1.18, 4, 2, 20.16, 9.8, 24.13, 15
破译原则如下:
1) 每个数字串的最后一个数为密码钥匙(它不是密码原文),设为key。每个数表示译文中的一个大写英文字母,用这些数减去key后所得到的值经适当修改后,为大写英文字母的相应序号。例如,相减后的值为1,对应的字母为A。修正方法为:①若相减后的值小于或等于零,则将其加上26。②若相减后的值大于26(当Key为负数时),则将其减去26。
2) 密码中的逗号为数字间的分隔符,密码中的圆点既是数字间的分隔符又代表译文中的空格。
假如一个密码为16,9.8,24,13,15
按照上述原则破译结果为“AT SIX”
将任给的若干条密码存入数据文件IN.DAT,设计程序,按上面的方法逐个进行破译。输出破译结果,并将结果输出到文件OUT.DAT中。

#include <stdio.h>
#include <string.h>
#define FILENAME_in "e:\input.dat" /*here to change the file adress*/
#define FILENAME_out "e:\output.dat" /*here to change the file adress*/

void transact(void)
{
FILE *fp;
int data_long,i=0,j=0,k=0,n=0;
int temp=0;
char s_data[64]="";
char data_end[32]="";
int data_num[64]={0};
char data_temp[64]="";

if ((fp=fopen(FILENAME_in,"r"))==NULL)
{
printf("cannot open file\n");
return;
}
fread(s_data,sizeof (s_data),1,fp);
fclose(fp);

data_long=strlen(s_data);
for(i = 0; i < data_long; i++)/*here to transact the data*/
{
if (s_data[i]>='0'&&s_data[i]<='9')
{
data_num[j]=(s_data[i]-48)+data_num[j]*10;
}
else if (s_data[i]==',')
{
j++;
}
else if (s_data[i]=='.')
{
j++;
data_temp[k]=j;
j++;
k++;
}
else goto loap2;
loap2:;
}

for (i=0;i<j;i++) /*here to code the data*/
{
if (k!=0)
{
if (n<=k)
{
if (i==data_temp[n])
{
data_end[i]=' ';
n++;
goto loap;
}
}
}
temp=data_num[i]-data_num[j];
if (temp>26||temp<1)
{
while (temp>26)
{
temp=temp-26;
}
while (temp<=0)
{
temp=temp+26;
}
}
data_end[i]=temp+96;
loap: ;
}

/*here to write the data*/
fp=fopen(FILENAME_out,"a+");
fwrite(data_end,sizeof(data_end),1,fp);
fprintf(fp,"\n");
fclose(fp);
}

void input_data(void)
{
FILE *fp;
char s_data[64]="";/*use to save intput data*/
char data_end[32]="";/*use to save end data*/
int a;/*to control*/
loap1: printf("1) continue. \n2) exit.\n3) clean the file.\n");
scanf("%d",&a);
if (a == 2)
{
return;
}
if (a == 1)
{
printf("please input your data:\n");
scanf("%s",s_data);

fp=fopen(FILENAME_in,"a+");
fwrite(s_data,sizeof(data_end),1,fp);
fprintf(fp,"\n");
fclose(fp);
transact();
goto loap1;
}
else if (a == 3)
{
fp=fopen(FILENAME_in,"w+");
fclose(fp);
fp=fopen(FILENAME_out,"w+");
fclose(fp);
goto loap1;
}
goto loap1;
}

main()
{
input_data();
}