Исходные тексты программ
Текст программы,
которая реализовывает проверку пароля
( он хранится в открытом виде в отдельном
файле)
#include
<stdio.h>
#include
<conio.h>
#include
<string.h>
char
arr_from_file[15];
char
arr_2[15];
void
test();
int
main()
{
test();
getch();
}
void
test()
{
int a=-1;
FILE *fp;
fp=fopen("password.txt", "r");
fgets(arr_from_file, 10, fp);
fclose(fp);
printf("Enter a password\n");
scanf ("%s", &arr_2);
if(strcmp(arr_from_file,arr_2)==0) a=0;
if(a==0) printf("the correct password");
else printf("the password is incorrect");
}
Текст программы,
которая исключает хранение файла в
открытом виде (использовали операцию
XOR)
include
<stdio.h>
#include
<conio.h>
#include
<string.h>
char arr_from_file[15];
char arr_2[15];
int
a=500, i;
void
test(){
if (a==0)printf("the correct password");
else printf("the password is incorrect\n");
}
int
main(){
FILE *ppassword = fopen("password_2.txt", "r");
fgets(arr_from_file, 10, ppassword);
fclose(ppassword);
int
N=strlen(arr_from_file);
for(i=0;
i<N; i++ ){
arr_from_file[i]=arr_from_file[i]^5;
}
printf("Enter
a password\n");
scanf
("%s", &arr_2);
N=strlen(arr_2);
for(i=0;
i<N; i++){
arr_2[i]=arr_2[i]^7;
}
if(strcmp(arr_from_file,arr_2)==0)
a=0;
test();
getch();
}
11