Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. UINT32 QTX_OPJMPENCRYPT(UINT32 instruction, int increment)
  2. {
  3. int i, j; // Loop counter
  4. UINT32 h = 0x2000009; // 1 | rotl(1,3) | rotr(1,7)
  5. UINT32 matrix[32]; // Matrix for set of boolean equations
  6. UINT32 y;
  7.  
  8. y = instruction ^ (0x1F3D8AF * increment); // XOR the constant
  9.  
  10. // Create matrix
  11. for (i = 0; i < 32; i++) {
  12. matrix[i] = rotl(h, i);
  13. }
  14.  
  15. // Solve using Gauss-Jordan
  16.  
  17. for (i = 0; i < 32; i++) {
  18. // If diagonal element is not one
  19. if (!(matrix[i] & 1U << i)) {
  20. // Search for row with 1
  21. for (j = i + 1; j < 32; j++) {
  22. if (matrix[j] & 1U << i) {
  23. // Swap row
  24. UINT32 tmp = matrix[i];
  25. matrix[i] = matrix[j];
  26. matrix[j] = tmp;
  27.  
  28. // Swap bit y[i] with y[j]
  29. y = (y & ~(1U << j | 1U << i)) | (y & 1U << j) >> (j - i) | (y & 1U << i) << (j - i);
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. // Find other rows with non-zero pivot
  36. for (j = 0; j < 32; j++) {
  37. if (j != i && matrix[j] & 1U << i) {
  38. // XOR row
  39. matrix[j] = matrix[j] ^ matrix[i];
  40.  
  41. // Set y[k] = y[k] xor y[i]
  42. if ((y & 1U << j) >> j == (y & 1U << i) >> i) {
  43. y = y & ~(1U << j); // set y[k] = 0 if y[k]==y[i]
  44. }
  45. else {
  46. y = y | (1U << j); // set y[k] = 1 if y[k]!=y[i]
  47. }
  48. }
  49. }
  50.  
  51.  
  52. }
  53.  
  54. return y;
  55.  
  56. }
  57. UINT32 QTX_OPCALLENCRYPT(UINT32 pc, UINT32 key)
  58. {
  59. UINT32 result = 0;
  60. UINT32 mask = 1;
  61. UINT32 loop = 32;
  62. UINT32 dec, ormask, andmask, andmask2;
  63.  
  64. for (UINT32 i = 0; i < 32; ++i)
  65. {
  66. dec = (key + 0x1F3D8AF * result) ^ (key - 0x1C6B438 * result - 0x541B9F);
  67. ormask = result | mask;
  68. andmask = mask & dec;
  69. andmask2 = mask & pc;
  70. mask *= 2;
  71. if (andmask == andmask2)
  72. ormask = result;
  73. result = ormask;
  74. }
  75. return result;
  76. }
  77.  
  78. UINT32 QTX_OPTAILCALLENCRYPT(UINT32 pc, UINT32 key)
  79. {
  80. UINT32 result = 0;
  81. UINT32 mask = 1;
  82. UINT32 loop = 32;
  83. UINT32 dec, ormask, andmask, andmask2;
  84.  
  85. for (UINT32 i = 0; i < 32; ++i)
  86. {
  87. ormask = result | mask;
  88. andmask = mask & ((key + 0x961C86 * result) ^ (0x1F3D8AF * result + result - 0x1C0BCC3));
  89. andmask2 = mask & pc;
  90. mask *= 2;
  91. if ( andmask == andmask2 )
  92. ormask = result;
  93. result = ormask;
  94. }
  95. return result;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement