#include
#include
#include
#include
int main(int argc, char ** argv){
/*
* Read a file. for each character, offset by N for the first value,
* for every other value, N+previous char value.
* Example: enigma -n 3 ABC
* A+3=D=4
* B+4= G=6
* C+7=J=10
* */
if(argc !=3){
printf("Usage: %s \n", argv[0]);
return -1;
}
int offset = atoi(argv[1]);
//printf("Offset : %d\n",offset);
FILE *file1=fopen(argv[2], "r"); //file to decode
if(file1==NULL ){
printf("Input Files ( %s ) Not Found\n", argv[2]);
return 0;
}
int count =0;
char c; //file io char
unsigned int p; // previous character Index
while(c!=EOF){
c =tolower(fgetc(file1));
if (count ==0){
p=c+offset;
//p=offset;
printf("char: %c Offset: %d value: %c \n",c,offset,c+offset);
count ++;
offset=p;
}
if (isalpha(c)>=97 || isalpha(c)<=122){
//get the previous index plus the index of the current value c
//offset = p + (c-'a'+1);
p=p-c-'a';
printf("P: %d \n",p);
offset = p + (c-'a'+1);
//p=p+ (c-'a');
// offset = 1;
//printf("char: %c Offset: %d value: %c \n",c,offset, c+offset);
//deal with other non alphabet characters here
printf(" ");
}
}
//sleep(10);
//system("clear");
return 0;
}