-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryptints.c
More file actions
32 lines (24 loc) · 914 Bytes
/
decryptints.c
File metadata and controls
32 lines (24 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
if (argc != 2) {
perror("Exactly two arguments needed");
return EXIT_FAILURE;
}
FILE* file = fopen(argv[1], "r");
unsigned int num;
int count = 0;
// While loop to iterate through each unsigned integer in the file
while (fscanf(file, "%u", &num) == 1) {
// Getting the number of wanted byte
count %= 4;
// Shifting by 8 bits (1 byte) times the number (1-4) that count is, & operation is necessary to only select the first 8 little-endian
// bits. OxFF is 11111111, so when it ands with an unsigned integer (which is 24 bits long after the shift), it only keeps the first ones the same
char cur_char = (char) (num >> (8 * count) & 0xFF);
printf("%c", cur_char);
count++;
}
fclose(file);
return 0;
}