Advertisement
pasholnahuy

Untitled

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