-
Notifications
You must be signed in to change notification settings - Fork 0
/
steg-decode.c
64 lines (55 loc) · 1.5 KB
/
steg-decode.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* steg-decode.c
* Řešení IJC-DU1
* Autor: Tomáš Matuš, FIT
* Login: xmatus37
* Datum: 15.3.2021
* Přeloženo: gcc 10.2.0
*/
#include "ppm.h"
#include "eratosthenes.h"
#include "error.h"
#include "bitset.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main(int argc, char **argv) {
if (argc != 2) {
error_exit("Pouze 1 vstupni argument!\n");
}
struct ppm *img = ppm_read(argv[argc - 1]);
if (img == NULL) {
error_exit("Obrazek nelze nacist\n");
}
unsigned arrSize = 3 * img->xsize * img->ysize;
bitset_alloc(p,arrSize)
Eratosthenes(p);
unsigned char msgByte = 0;
int count = 0;
for (unsigned i = 23; i < arrSize; i++) {
// index is prime
if (bitset_getbit(p,i) == 0) {
// get LSB from image data and put it to index in byte starting from LSB
msgByte |= ((img->data[i] & 1) << count);
count++;
// last bit in byte is filled
if (count == CHAR_BIT) {
count = 0;
putchar(msgByte);
// end of message
if (msgByte == '\0') {
putchar('\n');
break;
}
// message doesn't end with '\0'
if (i == arrSize - 1) {
warning_msg("Skryta zprava je nespravne ukoncena!\n");
}
msgByte = 0;
}
}
}
ppm_free(img);
bitset_free(p)
return 0;
}