Decryption

I have to decrypt two files(Cryptogram1 and Cryptogram2). I have the program that encrypted the files, and I have to switch part of it in order to change program to decryption.


Cryptogram1:obsirb`tmazpkqxejvvyswvjsqzyuqsatmrdelxekirrirzmluturwgas`fgwdxwsns`wwskjidpdgsxaazir

Cryptogram1 is encrypted with the key: surprise

Cryptogram2:obsirb`tmazpkqxejvvyswvjsqzyuqsatmrdelxekirrirzmluturwgas`fgwdxwsns`wwskjidpdgsxaazir

Cryptogram2 encrypted with the key: engineer
I was told that I should change the last portion of this encryption program in order to complete my assignment.


What should I change in order to achieve my goal.



Encryption Program:



#include<stdio.h>
main()
{
FILE *fpin, *fpout;
char Stringarray[100];
char datafile[20];
char outfile[20];
char key[8];
short theChar, keySize;
short n, temp1, temp2;

keySize=8;
printf("\n this program will read in a character string");
printf("\n enter the char string filename:");
scanf("%s", datafile);
printf("\n enter an 8-char key:");
scanf("%s",key);

if ((fpin=fopen(datafile,"r"))==NULL)
{
printf("Open input file error:%s is not found.\n", datafile);
return 0;
}

printf("\n enter the output filename:");
scanf("%s",outfile);
if ((fpout=fopen(datafile,"r"))==NULL)
{
printf("Open input file error:%s\n",outfile);
fclose(fpin);
return 0;
}
printf("\n enter the output filename:");
scanf("%s",outfile);

if ((fpout = fopen(outfile,"w")) == NULL)
{
printf('Open output file error:%s\n", outfile);
fclose(fpin);
return 0;
}

theChar = fgetc(fpin);
n=0;
while (theChar != EOF)
{
temp1=theChar-96;
n=n % 8;
if(temp1>0)
temp2=(temp1+key[n]-96)%27;
else
temp2=(key[n]-96)%27;
//fprintf(fpout,"%s",temp2);

fputc(temp2+96,fpout);
theChar = fgetc(fpin);
n++;
}
fclose(fpin);
fclose(fpout);
return 0;
}
Last edited on
not sure, but atleast this will give people more incentive to even consider your question >_>

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
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
main()
{
FILE *fpin, *fpout;
char Stringarray[100];
char datafile[20];
char outfile[20];
char key[8];
short theChar, keySize;
short n, temp1, temp2;

keySize=8;
printf("\n this program will read in a character string");
printf("\n enter the char string filename:");
scanf("%s", datafile);
printf("\n enter an 8-char key:");
scanf("%s",key);

if ((fpin=fopen(datafile,"r"))==NULL)
{
printf("Open input file error:%s is not found.\n", datafile);
return 0;
}

printf("\n enter the output filename:");
scanf("%s",outfile);
if ((fpout=fopen(datafile,"r"))==NULL)
{
printf("Open input file error:%s\n",outfile);
fclose(fpin);
return 0;
}
printf("\n enter the output filename:");
scanf("%s",outfile);

if ((fpout = fopen(outfile,"w")) == NULL)
{
printf("Open output file error:%s\n", outfile);
fclose(fpin);
return 0;
}

theChar = fgetc(fpin);
n=0;
while (theChar != EOF)
{
temp1=theChar-96;
n=n % 8;
if(temp1>0)
temp2=(temp1+key[n]-96)%27;
else
temp2=(key[n]-96)%27;
//fprintf(fpout,"%s",temp2);

fputc(temp2+96,fpout);
theChar = fgetc(fpin);
n++;
}
fclose(fpin);
fclose(fpout);
return 0;
}


edit:: well for one, you had a ' where you shoulda had a " .. i edited it out for you though
Last edited on
I love all those magic numbers:
1
2
3
4
5
6
temp1=theChar-96;
n=n % 8;
if(temp1>0)
temp2=(temp1+key[n]-96)%27;
else
temp2=(key[n]-96)%27;
What could they possibly mean?
Topic archived. No new replies allowed.