Guest User

Untitled

a guest
Jan 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. unsigned char getBit(unsigned char c, int n)
  4. {
  5. return (c & (1 << n)) >> n;
  6. }
  7.  
  8. unsigned char setBit(unsigned char c, int n)
  9. {
  10. return c | (1 << n);
  11. }
  12.  
  13. unsigned char clearBit(unsigned char c, int n)
  14. {
  15. return c & (~(1 << n));
  16. }
  17.  
  18. unsigned char switchBits(unsigned char c, unsigned char key)
  19. {
  20. int j;
  21. for (j = 0; j < 8; j += 2)
  22. {
  23. if (getBit(c,j) != getBit(c,j+1) && getBit(key,j) == 1)
  24. {
  25. if (getBit(c,j+1) == 1)
  26. {
  27. c = setBit(c,j);
  28. c = clearBit(c,j+1);
  29. }
  30. else
  31. {
  32. c = setBit(c,j+1);
  33. c = clearBit(c,j);
  34. }
  35. }
  36. }
  37. return c;
  38. }
  39.  
  40. unsigned char rotl(unsigned char c)
  41. {
  42. char last = getBit(c,7);
  43. c = c << 1;
  44. if (last == 1)
  45. c = setBit(c,0);
  46. return c;
  47. }
  48.  
  49. void printBits(unsigned char c)
  50. {
  51. int i;
  52. for (i = 7; i >= 0; i--)
  53. printf("%d", (c & (1 << i)) >> i);
  54. printf("\n");
  55. }
  56.  
  57. int main()
  58. {
  59.  
  60. unsigned char ciphertext[] = {16,48,16,48,32,0,32,0,16,48,16,48,32,0,32,0,16,48,16,48,32,0,32,0,16,48,16,48,32,0,32,0,16,48,168,250,191,253,110,55,86,35,3,142,207,95,153,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,83,190,147,189,160,77,144,190,116,4,40,8,20,56,40,8,40,4,40,8,106,56,150,200,85,7,43,11,23,59,43,11,43,7,43,11,23,59,43,11,43,7,43,11,23,59,43,11,43,7,75,11,71,11,139,155,123,151,187,171,135,107,139,155,123,151,187,171,135,107,139,155,123,151,187,251,183,251,123,107,139,103,75,91,119,7,13,114,145,113,82,113,97,129,81,114,145,113,47,114,28,130,236,177,239,207,239,159,191,95,191,175,79,175,143,159,191,95,191,175,79,175,143,159,191,95,191,175,239,111,47,95,47,15,31,63,31,63,31,63,47,15,31,63,31,63,31,63,47,15,31,111,47,175,239,159,239,207,223,175,239,207,239,163,149,229,197,214,245,217,246,229,201,229,197,214,245,103,54,88,10,152,120,56,184,244,216,248,228,200,216,248,216,244,216,248,228,200,216,248,216,244,216,248,228,104,136,200,72,164,136,152,180,88,184,168,72,164,136,152,180,88,184,248,120,52,24,56,36,8,136,200,72,4,40,8,68,8,136,200,232,88,81,30,62,30,62,45,14,46,13,30,62,30,62,80,13,147,206,221,253,125,61,46,13,45,14,29,61,29,61,46,13,45,14,29,61,29,61,46,13,141,206,141,157,221,109,78,173,77,110,77,93,189,109,78,173,77,110,77,93,29,173,222,93,189,158,189,253,221,253,238,205,77,14,77,13,141,93,18,24,168,132,148,184,84,180,164,68,168,132,148,184,234,116,25,135,107,71,7,75,167,71,87,183,91,119,103,75,167,71,87,183,91,119,103,75,167,71,87,23,155,215,167,219,247,231,199,231,203,135,151,187,87,183,167,71,171,135,199,139,199,71,87,183,91,119,103,75,167,71,87,183,251,183,167,139,251,241,142,109,141,174,141,157,125,173,142,109,141,174,141,227,125,19,78,13,141,211,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,19,99,35,3,35,3,19,51,35,83,19,51,19,51,35,3,19,51,19,147,211,163,211,243,227,195,227,195,227,195,211,243,227,147,211,243,211,159,169,217,249,147,202,80,5,22,58,22,54,37,6,42,120,21,71,21,139,203,75,7,43,11,23,59,43,11,43,7,43,11,23,59,43,11,43,7,43,11,23,155,235,155,123,151,187,171,215,91,187,171,75,167,139,155,183,91,187,171,235,103,75,91,119,155,123,107,139,249,139,246,132,200,72,8,40,152,145,222,254,104,50,88,1,33,2,17,49,17,49,95,2,130,193,130,194,66,2,65,162,66,97,66,82,178,98,65,162,66,97,66,82,178,98,65,162,66,97,66,2,130,82,113,146,210,145,226,146,114,162,129,98,130,161,130,146,114,162,129,98,130,161,130,252,66,60,65,63,129,194,129,193,65,145,222,212,100,72,88,116,152,120,104,136,196,136,200,132,104,54,88,5,137,198,133,153,117,165,134,101,137,166,133,153,117,165,134,101,137,166,133,153,117,165,134,101,137,166,133,153,117,165,214,85,25,86,117,105,133,85,118,149,121,86,117,105,133,251,134,248,74,56,69,55,133,251,235,203,71,11,75,87,39,29,82,177,81,114,97,65,161,209,162,225,193,226,193,175,241,95,2,156,124,92,124,108,140,92,124,156,124,92,124,108,140,92,124,156,124,92,44,92,188,108,76,172,76,108,76,92,188,252,188,92,188,156,188,172,76,156,188,193,127,2,124,2,188,194,188,193,127,2,124,2,188,252,188,92,28,60,64,70,54,38,85,22,154,213,166,218,86,38,85,11,153,203,166,244,216,248,184,248,212,248,232,196,232,200,216,248,212,248,232,196,232,200,216,248,116,56,120,100,136,88,120,152,116,88,120,100,136,88,120,152,116,5,123,9,187,197,187,198,116,5,123,9,187,197,187,198,116,5,123,9,187,107,27,155,235,226,173,221,93,189,254,125,61,126,61,125,61,147,206,80,14,80,13,77,13,29,62,29,61,30,61,45,13,29,62,29,61,30,61,45,13,29,110,45,173,142,157,189,93,189,174,77,173,142,157,211,109,35,110,16,174,208,157,211,109,35,110,16,174,208,157,211,109,35,110,16,174,208,157,211,109,35,111,166,214,153,234,198,74,10,73,10,38,116,25,75,25,135,234,116,56,116,52,40,4,20,52,20,56,20,52,40,4,20,52,20,56,20,52,120,52,180,244,212,248,212,244,232,196,122,4,185,203,186,196,182,196,122,4,185,203,186,196,182,196,122,105,138,102,73,90,118,154,122,4,185,203,186,196,182,198,204,176,80,176,144,176,240,112,160,128,221,67,30,64,46,14,30,109,46,174,141,158,190,94,190,173,78,174,141,158,190,94,190,173,78,174,141,206,222,254,238,160,221,99,30,80,30,160,238,160,221,99,30,80,30,160,238,160,221,253,222,253,237,205,77,14,45,13,78,93,125,157,125,110,141,243,142,241,247,71,151,183,87,187,247,183,213,71,41,119,42,184,233,202,214,90,42,89,186,246,217,250,230,202,218,249,218,246,217,250,230,202,218,249,218,104,25,87,21,167,233,167,218,104,25,87,21,167,233,167,218,104,25,58,118,58,186,169,74,166,233,154,230,202,218,249,122,150,185,170,134,106,138,153,122,10,0,124,108,140,92,124,156,220,156,193,175,241,95,2,156,194,129,146,226,98,18,49,18,50,17,50,34,2,18,49,18,50,76,49,79,49,143,242,76,50,76,49,79,49,143,242,76,50,76,49,79,175,79,95,191,95,31,111,79,175,79,95,31,159,223,255,191,255,127,111,143,111,79,95,11,39,7,123,178,206,237,206,222,254,238,157,195,93,3,110,48,174,240,157,195,67,3,67,83,19,51,35,3,189,195,190,192,126,0,125,3,189,195,190,192,126,0,125,3,189,195,190,192,126,0,64,0,128,160,128,144,112,160,128,96,128,160,128,144,112,48,112,48,176,240,176,240,208,240,224,192,224,192,128,192,124,182,201,234,198,233,202,214,90,4,105,55,165,215,154,216,106,36,105,23,165,215,167,229,87,25,87,42,152,233,167,229,87,25,87,42,152,233,167,229,87,25,87,183,91,119,103,27,151,231,151,215,251,215,247,235,199,215,247,215,251,215,247,235,103,23,103,39,11,39,7,27,55,39,7,39,11,71,59,49,141,93,126,157,125,35,126,16,144,224,189,94,32,93,19,93,35,173,227,94,32,93,19,93,35,173,227,94,32,93,19,93,35,173,227,94,32,0,16,48,16,48,32,0,32,96,16,48,16,48,32,0,32,0,16,48,16,48,32,0,32,96,16,96,32,144,176,80,176,144,176,160,64,0,64,160,220,217,150,186,86,182,165,70,20,69,43,121,43,11,27,59,23,59,70,52,134,248,133,251,73,59,70,52,134,248,133,251,73,59,43,7,43,11,27,59,23,59,43,7,43,11,27,59,23,59,43,7,43,11,27,59,23,59,43,7,43,11,27,155,215,155,235,151,219,251,235,203,231,203,139,199,75,155,215,222,98,65,82,114,44,12,97,63,161,255,239,207,239,207,223,255,223,255,239,207,113,15,114,12,178,145,178,162,66,146,177,82,178,145,178,162,66,146,177,82,178,145,178,162,66,146,177,82,178,145,178,162,66,146,177,82,178,145,226,146,210,242,225,194,226,193,210,242,210,242,225,98,34,97,18,98,30,36,104,136,100,72,37,9,155,197,171,246,218,245,230,202,230,198,213,246,218,245,230,202,230,198,213,246,218,245,230,202,230,198,213,246,218,245,230,202,230,198,213,246,218,245,230,202,230,198,213,246,218,245,230,202,230,198,213,86,26,85,38,10,38,6,21,54,26,53,38,10,38,6,21,150,218,245,138,128,252,236,204,236,114,81,15,97,63,145,178,81,177,146,177,161,65,145,178,81,177,146,177,161,65,145,178,81,177,146,177,161,65,145,178,81,177,146,177,161,65,145,178,81,177,146,177,161,65,145,178,81,177,146,177,161,65,145,226,97,33,2,17,49,17,49,34,1,33,2,17,49,17,49,114,49,141,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,75,170,139,149,180,85,184,166,108,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,133,150,186,86,182,165,70,170,240,224,192,86,57,109,142,205,168,236,169,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,131,147,115,147,179,163,131,99,61,46,13,160,207,185,235,95,62,103,10,181,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,175,143,111,143,159,127,159,191,255,239,207,123,10,175,198,186,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,160,64,144,176,80,176,144,176,206,238,206,188,214,96,10,120,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,146,114,97,130,98,65,82,114,38,6,21,143,224,141,218,183,201,94,122,10,38,81,19,122,23,148,210,96,9,3};
  61.  
  62. unsigned char key = 27;
  63. unsigned char new;
  64. int i;
  65.  
  66. for (i = 0; i < sizeof ciphertext; i++)
  67. {
  68. new = switchBits(ciphertext[i],key);
  69. if (i != 0)
  70. new = new ^ ciphertext[i-1];
  71. else
  72. new = new ^ 42;
  73. printf("%c", new);
  74. key = rotl(key);
  75. }
  76.  
  77. return(0);
  78. }
Add Comment
Please, Sign In to add comment