我这段代码printf在加密模块乱码,希望指点
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#define MAC_HEADER "Physical Address"
#define max 100
int encodeORdecode(int x,int a,int b){//加解密算法
int r=1;
do{
r*=x;
r=r%b;
a--;
}while(a!=0);
return r;
}
void encode(char *a){
int i,k;
int tmp[max];
printf("\n");
int t=strlen(a);
int p=11,q=13;
int n,f,e;
n=p*q;
f=(p-1)*(q-1);
e=7;
//printf("两个公钥分别是:e=%d n=%d\n",e,n);
//int d=1;
//while((d*e)%f!=1) d++; //形成私钥
printf("\n");
for( k=0;k<t;k++) tmp[k]=a[k];
for( i=0;i<t;i++)
a[i]=encodeORdecode(tmp[i],e,n);
printf("加密后字符串为:");
for(i=0;i<t;i++) printf("%c",a[i]); printf("\n");
}
void deencode(char *a){
int i;
int c[max];
int tmp[max];
printf("\n");
int t=strlen(a);
int p=11,q=13;
int n,f,e;
n=p*q;
f=(p-1)*(q-1);
e=7;
//printf("两个公钥分别是:e=%d n=%d\n",e,n);
int d=1;
while((d*e)%f!=1) d++; //形成私钥
for( i=0;i<t;i++) tmp[i]=a[i];
for( i=0;i<t;i++)
c[i]=encodeORdecode(tmp[i],d,n);
printf("解密后字符串为:");
for( i=0;i<t;i++) printf("%c",c[i]); printf("\n");
}
void tiquMAC(char *mac)
{
int argc=0;
char * argv [100 ]={0};
char *netname = "本地连接";
char buf [4096];
FILE *fp;
char *tmp;
int size;
if(argc == 2) netname = argv[1];
system("ipconfig /all > tmp.txt");
fp = fopen("tmp.txt", "r");
if(fp == NULL)
{
printf("can not find tmp.txt, please check \n");
}
fseek(fp, 0, SEEK_END);
size = ftell(fp);
if(size >= sizeof(buf))
{
printf("the buffer size is too small, should be more than %d\n", size);
fclose(fp);
}
fseek(fp, 0, SEEK_SET);
memset(buf, 0, sizeof(buf));
fread(buf, 1, size, fp);
fclose(fp);
tmp = strstr(buf, netname);
if(tmp == NULL)
{
printf("can not find network name %s, please check your network name\n", netname);
}
tmp = strstr(tmp, MAC_HEADER);
if(tmp == NULL)
{
printf("no "MAC_HEADER"found in file, please check\n");
printf("are you using chinese windows? if so, please check in file and change the MAC_HEADER define\n");
}
tmp = strstr(tmp, ":");
if(tmp)
{
memset(mac, 0, sizeof(mac));
memcpy(mac, &tmp[2], 17);
mac[17]='\0';
}
remove("tmp.txt");
}
int main(){
char a[100]={0};
tiquMAC(a);
for(int i=0;a[i]!='\0';i++)
printf("%c",a[i]);
//printf("\n");
encode(a);
deencode(a);
return 0;
}