Result:
Write file name:
my_normal_with_date_file1
Write code file name:
my_code_with_date_file1
------------------
(program exited with code: 0)
Press return to continue
cat my_normal_with_date_file1
Sat Jan 14 11:38:50 2017
cat my_code_with_date_file1
Qzu;Qzu;*(!*();*+)*;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
using namespace std;
void init_Random()
{
srand(time(NULL));
}
char *my_xor(char *text, char key)
{
int i,j;
char *temp_text=new char[48];
j=strlen(text);
for(i=0;i<j+1;i++)
temp_text[i]=text[i]^key;
return temp_text;
}
char *plus_text(char *text)
{
int i,j;
char *temp_text=new char[48];
j=strlen(text);
for(i=0;i<j+1;j++)
temp_text[i]=255+text[i];
return temp_text;
}
char *minus_text(char *text)
{
int i,j;
char *temp_text=new char[48];
j=strlen(text);
for(i=0;i<j+1;i++)
temp_text[i]=255-text[i];
return temp_text;
}
char *random_text(char *text)
{
int i,j;
i=rand()%3;
char *temp_text;
switch(i)
{
case 0: j=rand()%255; temp_text=my_xor(text,j);break;
case 1: temp_text=plus_text(text);break;
case 2: temp_text=minus_text(text);break;
}
return temp_text;
}
char *now_time()
{
time_t n_time=time(NULL);
return asctime(localtime(&n_time));
}
int main(int argc, char **argv)
{
init_Random();
char file_name[48],code_name[48];
printf("Write file name:\n ");
scanf("%s",file_name);
printf("Write code file name:\n ");
scanf("%s",code_name);
char *time_text;
char *code_text;
time_text=now_time();
code_text=random_text(time_text);
int file_open;
size_t file_length;
file_length=strlen(time_text);
file_open=open(file_name,O_WRONLY | O_CREAT | O_APPEND, 0666);
write(file_open,time_text,file_length);
close(file_open);
FILE *next_file;
next_file=fopen(code_name,"w");
fprintf(next_file,"%s",code_text);
fclose(next_file);
return 0;
}
Brak komentarzy:
Prześlij komentarz