Advertisement
pasholnahuy

Untitled

Dec 20th, 2023
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <inttypes.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6.  
  7. int main(int argc, char *argv[]) {
  8.     char *input = argv[1];
  9.     char *output = argv[2];
  10.     int input_filedesc = open(input, O_RDONLY);
  11.     int output_filedesc =
  12.         open(output, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  13.     int32_t mod = atoi(argv[3]);
  14.     int read_bytes;
  15.     uint64_t ind = 1;
  16.     uint64_t sum = 0;
  17.     uint8_t buf;
  18.     while ((read_bytes = read(input_filedesc, &buf, 1)) == 1) {
  19.         for (size_t i = 0; i < (1 << 3); ++i) {
  20.             sum = (sum + (ind * ind) % mod) % mod;
  21.             if ((buf & (1 << i)) >> i) {
  22.                 if (write(output_filedesc, &sum, sizeof(int32_t)) ==
  23.                     sizeof(int32_t)) {
  24.                 }
  25.             }
  26.             ++ind;
  27.         }
  28.     }
  29.     close(input_filedesc);
  30.     close(output_filedesc);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement