Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef unsigned char u8;
- typedef char s8;
- typedef unsigned short u16;
- typedef short s16;
- typedef unsigned int u32;
- typedef int s32;
- typedef unsigned long long u64;
- typedef long long s64;
- typedef struct {
- u8 bgrb;
- u8 bgrg;
- u8 bgrr;
- }bgr;
- void deskript() {
- printf("test\n");
- }
- void encript() {
- printf("vvedite file bmp, a potom .....\n");
- char nazv1[50];
- char nazv2[50];
- scanf("%s",nazv1);
- FILE* infile = fopen(nazv1,"rb");
- if (infile == NULL) {
- printf("ne udalos' otkrit' infile");
- exit(1);
- }
- scanf("%s",nazv2);
- FILE* outfile = fopen(nazv2,"wb");
- if (outfile == NULL) {
- printf("ne udalos' otkrit' outfile");
- exit(1);
- }
- u8 sch;
- sch = 'm';
- fwrite(&sch,sizeof(u8),1,outfile);
- sch = 's';
- fwrite(&sch,sizeof(u8),1,outfile);
- sch = 'f';
- fwrite(&sch,sizeof(u8),1,outfile);
- sch = 'k';
- fwrite(&sch,sizeof(u8),1,outfile);
- sch = 'a';
- fwrite(&sch,sizeof(u8),1,outfile);
- sch = 3; //szhatiye 1-y bit i kommentariy 2-y but
- fwrite(&sch,sizeof(u8),1,outfile);
- u8 i = 0;
- sch = 0;
- while (i < 128) { //kommentariy 128 bites
- fwrite(&sch,1,1,outfile);
- i++;
- }
- u64 width;
- u64 height;
- fseek(infile,18,SEEK_CUR);
- fread(&width,4,1,infile);
- fread(&height,4,1,infile);
- fwrite(&width,4,1,outfile);
- fwrite(&height,4,1,outfile);
- fseek(infile,54,SEEK_SET);
- u8 nuli = 4-((width*3)%4);
- if (nuli == 4) { nuli = 0; }
- bgr tri;
- u64 hek = 0;
- u64 wik;
- while (hek < height) {
- wik = 0;
- while (wik < width) {
- fread(&tri,sizeof(bgr),1,infile);
- fwrite(&tri,sizeof(bgr),1,outfile);
- wik++;
- }
- hek++;
- fseek(infile,nuli,SEEK_CUR);
- }
- fclose(infile);fclose(outfile);
- }
- int main() {
- printf("1 eto raskodirovat', 2 eto zakodirovat'\n");
- char rezh[1];
- scanf("%s",rezh);
- if (rezh[0] == '1') {
- deskript();
- }
- else {
- encript();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement