Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <inttypes.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main(int argc, char *argv[]) {
- int input_file = open(argv[1], O_RDONLY);
- int ouput_file =
- open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
- uint32_t mod = atoll(argv[3]);
- uint64_t current_sum = 0;
- uint64_t current_x = 0;
- uint8_t buffer;
- while (read(input_file, &buffer, 1) == 1) {
- for (int i = 0; i < (1 << 3); ++i) {
- ++current_x;
- current_sum = (current_sum + current_x * current_x) % mod;
- if (buffer & (1 << i)) {
- if (write(ouput_file, ¤t_sum, 4) != 4) {
- continue;
- }
- }
- }
- }
- close(input_file);
- close(ouput_file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement