1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <stdio.h>
int main ()
{
FILE * message;
FILE * changed;
int encryptnumber;
int messagepart;
int choose;
me:
puts("When your message in in a file named \"message.txt\" press 1 for encrypt or 2 for Decrypt then enter.");
scanf( "%i" , &choose);
switch (choose) {
// encrypt
case 1:
printf("What number do you want to encrypt with? choose any number exept 0 or the encryption will not work:");
scanf( "%i" , encryptnumber);
message = fopen("message.txt" , "r");
changed = fopen("encrypted.txt" , "w");
for(;;)
{
fscanf( message , "%x" , &messagepart);
messagepart * encryptnumber;
fprintf( changed, "%x" , messagepart);
}
fclose(message);
fclose(changed);
break;
// decrypt
case 2:
printf("Enter your decrypt number:");
scanf( "%i" , encryptnumber);
message = fopen("message.txt" , "r");
changed = fopen("decrypted.txt" , "w");
for(;;)
{
fscanf( message , "%x" , &messagepart);
messagepart / encryptnumber;
fprintf( changed, "%x" , messagepart);
}
fclose(message);
fclose(changed);
break;
default:
puts("Only 1 or 2");
goto me;
}
}
|