Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void to_encrypt() {
  6.  
  7. char line[150], encrypted_line[150];
  8. int offset;
  9.  
  10. printf("Enter encryption offset: ");
  11. scanf("%d", &offset);
  12.  
  13. FILE *file = fopen("Test.txt", "r");
  14. FILE *encrypted_file = fopen("Test_Encrypted.txt", "w");
  15.  
  16. if (file == NULL)
  17. printf("Failed to open file.");
  18.  
  19. fgets(line, 150, file); /* testing to see if fgets() is reading the file*/
  20. printf("%s", line);
  21.  
  22. while (fgets(line, 150, file)) {
  23.  
  24. for (int c = 0; c <= (sizeof(line) / sizeof(line[0])); c++) {
  25. if (line[c] + offset >= 127) {
  26. encrypted_line[c] = 32 + ((line[c] + offset) - 127);
  27. } else {
  28. encrypted_line[c] = line[c] + offset;
  29. }
  30.  
  31. }
  32.  
  33. printf("%s", encrypted_line);
  34. fprintf(encrypted_file, "%s\n", encrypted_line);
  35.  
  36. }
  37.  
  38.  
  39. fclose(file);
  40. fclose(encrypted_file);
  41.  
  42. }
  43.  
  44.  
  45. void to_decrypt(void) {
  46.  
  47.  
  48.  
  49. }
  50.  
  51.  
  52. int main() {
  53.  
  54. to_encrypt();
  55.  
  56. return 0;
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement