Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h> //random
- #include <string.h> // char commands
- #include <windows.h> //for colors [works only on windows]
- //codes a text that the user inputs with the delay requested then decodes it in a file.
- int main ()
- {
- char str1[500];
- int delay = 0;
- int codedelay = 0;
- int chainlength = 0;
- int i = 0;
- FILE* fichier = NULL;
- fichier = fopen("decoder.txt", "w+");
- if(fichier != NULL)
- {
- printf("Write a text\n\n");
- fprintf(fichier, "Your text: \n\n");
- fgets(str1, 1000, stdin);
- fprintf(fichier, "%s", str1);
- printf("How much delay should there be to your text(you may use negative delay too)?\n\n");
- scanf("%d", &delay);
- chainlength = strlen(str1);
- for(i = 0; i < chainlength; i++)
- {
- codedelay = str1[i]+delay;
- str1[i] = codedelay;
- }
- fprintf(fichier, "\n\nYour text coded:\n\n%s", str1);
- for(i = 0; i < chainlength; i++)
- {
- codedelay = str1[i]-delay;
- str1[i] = codedelay;
- }
- fprintf(fichier, "\n\nYour text decoded : \n\n%s", str1);
- }
- else
- {
- printf("File could not be open");
- }
- fclose(fichier);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement