Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <inttypes.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main(int argc, char *argv[]) {
- char *input = argv[1];
- char *output = argv[2];
- int input_filedesc = open(input, O_RDONLY);
- int output_filedesc =
- open(output, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
- int32_t mod = atoi(argv[3]);
- int read_bytes;
- uint64_t ind = 1;
- uint64_t sum = 0;
- uint8_t buf;
- while ((read_bytes = read(input_filedesc, &buf, 1)) == 1) {
- for (size_t i = 0; i < (1 << 3); ++i) {
- sum = (sum + (ind * ind) % mod) % mod;
- if ((buf & (1 << i)) >> i) {
- if (write(output_filedesc, &sum, sizeof(int32_t)) ==
- sizeof(int32_t)) {
- }
- }
- ++ind;
- }
- }
- close(input_filedesc);
- close(output_filedesc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement