Advertisement
Guest User

Untitled

a guest
May 28th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. void midcrypt(unsigned char key[6], unsigned char in[16], unsigned char out[16]) {
  2. for (int i = 0; i < 16; ++i) {
  3. out[i] = in[i];
  4. }
  5. for (int k = 0; k < 6; ++k) {
  6. unsigned char x = key[k];
  7. for (int r = 0; r < 100; ++r) {
  8. for (int i = 0; i < 16; ++i) {
  9. x = x * 5 + 1;
  10. ::global_x[k] =x;
  11. out[i] ^= x;
  12. out[i] = sbox[out[i]];
  13. }
  14. int first = out[0];
  15. for (int i = 0; i < 15; ++i) {
  16. out[i] = (out[i] << 3) ^ (out[i+1] >> 5);
  17. }
  18. out[15] = (out[15] << 3) ^ (first >> 5);
  19. }
  20. }
  21. }
  22.  
  23. void decrypt (unsigned char key[6], unsigned char crypted[16], unsigned char decr[16]) {
  24. for (int i = 0; i < 16; i++) {
  25. decr[i] = crypted[i];
  26. }
  27. for (int k = 5; k >= 0; k--) {
  28. unsigned char x = ::global_x[k];
  29. for (int r = 0; r < 100; r++) {
  30. int first = decr[15];
  31. int i;
  32. for (i = 15; i > 0; i--) {
  33. decr[i] = (((decr[i]) >> 3) ^ (decr[i-1] << 5));
  34. }
  35. decr[0] = ((decr[0] >> 3) ^ (first << 5 )) ;
  36. for (int i = 0; i < 16; i++) {
  37. unsigned int j;
  38. for (j = 0; j < sizeof(sbox); j++) {
  39. if (decr[i] == sbox[j])
  40. break;
  41. }
  42. decr[i] = j;
  43. decr[i] ^= x;
  44. x = ((x - 1) * 205) % 256;
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement