bogdan2004333

Untitled

Nov 22nd, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "caesar.h"
  4.  
  5. //функция создает массив ключей
  6. int key_temp(FILE *text, char *arr, const char *arr1, int *arr3) {
  7.     char *token;
  8.     int n = 0;
  9.     int i = 0;
  10.     int j = 0;
  11.     while ((fgets(arr, 1024, text)) != NULL) {
  12.         token = strtok(arr, arr1);
  13.         i = 0;
  14.         while (token != NULL) {
  15.             if (*(arr + i) != NULL) {
  16.                 n += (int) *(arr + i);
  17.                 i++;
  18.             } else {
  19.                 n/=128;
  20.                 *(arr3 + j) = n;
  21.                 j++;
  22.                 n = 0;
  23.                 i++;
  24.                 token = strtok(NULL, arr1);
  25.             }
  26.         }
  27.     }
  28.     return *(arr3 + i);
  29. }
  30.  
  31. //функция кодирует инфу
  32. void coding(FILE *source,FILE *code,const int *arr) {
  33.     char c;
  34.     c = getc(source);
  35.     int i = 0;
  36.     while (!feof(source)) {
  37.  
  38.         c += *(arr + i);
  39.         if (c > 127)
  40.             c -= 127;
  41.         fprintf(code, "%c", c);
  42.         i++;
  43.         if (i > 170) {
  44.             i = 0;
  45.         }
  46.         c = getc(source);
  47.  
  48.     }
  49. }
  50. //функция декодирует инфу
  51. void decoding(FILE *code,FILE *decode1,const int *arr) {
  52.     char c;
  53.     c = getc(code);
  54.     int i = 0;
  55.     while (!feof(code)) {
  56.         c -= *(arr + i);
  57.         if (c < 0)
  58.             c += 127;
  59.         fprintf(decode1, "%c", c);
  60.         i++;
  61.         if (i > 170) {
  62.             i = 0;
  63.         }
  64.         c = getc(code);
  65.  
  66.     }
  67. }
  68. //вывод текста
  69. void print_text(FILE *text,int len,char *arr){
  70.     while((fgets(arr,len,text))!=0){
  71.         printf("%s",arr);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment