Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef unsigned char u8;
  5. typedef char s8;
  6. typedef unsigned short u16;
  7. typedef short s16;
  8. typedef unsigned int u32;
  9. typedef int s32;
  10. typedef unsigned long long u64;
  11. typedef long long s64;
  12.  
  13. typedef struct {
  14. u8 bgrb;
  15. u8 bgrg;
  16. u8 bgrr;
  17. }bgr;
  18.  
  19.  
  20.  
  21. void deskript() {
  22. printf("test\n");
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. void encript() {
  31. printf("vvedite file bmp, a potom .....\n");
  32. char nazv1[50];
  33. char nazv2[50];
  34. scanf("%s",nazv1);
  35. FILE* infile = fopen(nazv1,"rb");
  36. if (infile == NULL) {
  37. printf("ne udalos' otkrit' infile");
  38. exit(1);
  39. }
  40. scanf("%s",nazv2);
  41. FILE* outfile = fopen(nazv2,"wb");
  42. if (outfile == NULL) {
  43. printf("ne udalos' otkrit' outfile");
  44. exit(1);
  45. }
  46. u8 sch;
  47. sch = 'm';
  48. fwrite(&sch,sizeof(u8),1,outfile);
  49. sch = 's';
  50. fwrite(&sch,sizeof(u8),1,outfile);
  51. sch = 'f';
  52. fwrite(&sch,sizeof(u8),1,outfile);
  53. sch = 'k';
  54. fwrite(&sch,sizeof(u8),1,outfile);
  55. sch = 'a';
  56. fwrite(&sch,sizeof(u8),1,outfile);
  57. sch = 3; //szhatiye 1-y bit i kommentariy 2-y but
  58. fwrite(&sch,sizeof(u8),1,outfile);
  59. u8 i = 0;
  60. sch = 0;
  61. while (i < 128) { //kommentariy 128 bites
  62. fwrite(&sch,1,1,outfile);
  63. i++;
  64. }
  65. u64 width;
  66. u64 height;
  67. fseek(infile,18,SEEK_CUR);
  68. fread(&width,4,1,infile);
  69. fread(&height,4,1,infile);
  70. fwrite(&width,4,1,outfile);
  71. fwrite(&height,4,1,outfile);
  72. fseek(infile,54,SEEK_SET);
  73. u8 nuli = 4-((width*3)%4);
  74. if (nuli == 4) { nuli = 0; }
  75. bgr tri;
  76. u64 hek = 0;
  77. u64 wik;
  78. while (hek < height) {
  79. wik = 0;
  80. while (wik < width) {
  81. fread(&tri,sizeof(bgr),1,infile);
  82. fwrite(&tri,sizeof(bgr),1,outfile);
  83. wik++;
  84. }
  85. hek++;
  86. fseek(infile,nuli,SEEK_CUR);
  87. }
  88. fclose(infile);fclose(outfile);
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. int main() {
  114. printf("1 eto raskodirovat', 2 eto zakodirovat'\n");
  115. char rezh[1];
  116. scanf("%s",rezh);
  117. if (rezh[0] == '1') {
  118. deskript();
  119. }
  120. else {
  121. encript();
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement