Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UINT32 QTX_OPJMPENCRYPT(UINT32 instruction, int increment)
- {
- int i, j; // Loop counter
- UINT32 h = 0x2000009; // 1 | rotl(1,3) | rotr(1,7)
- UINT32 matrix[32]; // Matrix for set of boolean equations
- UINT32 y;
- y = instruction ^ (0x1F3D8AF * increment); // XOR the constant
- // Create matrix
- for (i = 0; i < 32; i++) {
- matrix[i] = rotl(h, i);
- }
- // Solve using Gauss-Jordan
- for (i = 0; i < 32; i++) {
- // If diagonal element is not one
- if (!(matrix[i] & 1U << i)) {
- // Search for row with 1
- for (j = i + 1; j < 32; j++) {
- if (matrix[j] & 1U << i) {
- // Swap row
- UINT32 tmp = matrix[i];
- matrix[i] = matrix[j];
- matrix[j] = tmp;
- // Swap bit y[i] with y[j]
- y = (y & ~(1U << j | 1U << i)) | (y & 1U << j) >> (j - i) | (y & 1U << i) << (j - i);
- break;
- }
- }
- }
- // Find other rows with non-zero pivot
- for (j = 0; j < 32; j++) {
- if (j != i && matrix[j] & 1U << i) {
- // XOR row
- matrix[j] = matrix[j] ^ matrix[i];
- // Set y[k] = y[k] xor y[i]
- if ((y & 1U << j) >> j == (y & 1U << i) >> i) {
- y = y & ~(1U << j); // set y[k] = 0 if y[k]==y[i]
- }
- else {
- y = y | (1U << j); // set y[k] = 1 if y[k]!=y[i]
- }
- }
- }
- }
- return y;
- }
- UINT32 QTX_OPCALLENCRYPT(UINT32 pc, UINT32 key)
- {
- UINT32 result = 0;
- UINT32 mask = 1;
- UINT32 loop = 32;
- UINT32 dec, ormask, andmask, andmask2;
- for (UINT32 i = 0; i < 32; ++i)
- {
- dec = (key + 0x1F3D8AF * result) ^ (key - 0x1C6B438 * result - 0x541B9F);
- ormask = result | mask;
- andmask = mask & dec;
- andmask2 = mask & pc;
- mask *= 2;
- if (andmask == andmask2)
- ormask = result;
- result = ormask;
- }
- return result;
- }
- UINT32 QTX_OPTAILCALLENCRYPT(UINT32 pc, UINT32 key)
- {
- UINT32 result = 0;
- UINT32 mask = 1;
- UINT32 loop = 32;
- UINT32 dec, ormask, andmask, andmask2;
- for (UINT32 i = 0; i < 32; ++i)
- {
- ormask = result | mask;
- andmask = mask & ((key + 0x961C86 * result) ^ (0x1F3D8AF * result + result - 0x1C0BCC3));
- andmask2 = mask & pc;
- mask *= 2;
- if ( andmask == andmask2 )
- ormask = result;
- result = ormask;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement