#include <stdio.h>
#include <string.h>
#include "rot13.h"

main(){

char text[100], text2[100]; 

/*verschlüsselter Text wird ausgegeben und int text2
 * gespeichert
 */

char *textptr;
char a, ctrl, b;
int i, firsttime=0;


void crypt(char *text3){
  i=0;
  if(!text3){ 					/*Wenn kein Text übergeben wird*/
	  system("clear");
	  printf("Text to encrypt/decrypt: \n\n");
	  gets(text);
	  system("clear");
	  printf("encrypted/decrypted text: \n\n");
	  textptr=text;
  }  
  else {  					/*übergebenen Text verschlüsseln*/
	  textptr=text3;
	  system("clear");
	  printf("encrypted/decrypted text: \n\n");
  }

  while(i < strlen(text)){

    a=encrypt13(*textptr);	

    if (a !='0'){
		putchar(a);
		text2[i]=a;
	}
    else {
		putchar(*textptr);
		text2[i]=*textptr;
	}
    textptr++;
    i++;
  }
  printf("\n\n");
}


char ask(){
  if(firsttime==1){
    printf("NewText/Again/Quit? (n/a/enter): ");
    gets(&ctrl);
    system("clear");
    return(ctrl);
  }
  else{
    firsttime=1;
    return('n');
  }
}


system("clear");

while(b=ask()){
	if(b=='n') crypt('\0');       /*Bei neuem Text NullTerminator übergeben*/
	if(b=='a') crypt(text2);	  /*Bei again pointer aufgespeicherten Text */
}
system(0);


}
