SHARE
TWEET

fast PK3

luckytyphlosion Apr 10th, 2019 (edited) 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <string.h>
  4.  
  5. typedef unsigned int uint;
  6. typedef unsigned short u16;
  7. typedef unsigned char u8;
  8.  
  9. #define _A0F4 (_A0F3 >> 8) & 0xff
  10. #define _A0F5 (_A0F3 >> 16) & 0xff
  11. #define _A0F6 (_A0F3 >> 24) & 0xff
  12. #define TRUE 1
  13. #define FALSE 0
  14.  
  15. u8 sA567[] = {0x15, 0xc8, 0x7b, 0x6b, 0x7f, 0xa1, 0xa3, 0x29, 0xe8, 0x81, 0x1, 0x99, 0x9f, 0xeb, 0xf2, 0x80, 0x5f, 0xa3, 0x96, 0x7c, 0x17, 0xdb, 0xd2, 0x41, 0xa1, 0xbc, 0xbb, 0x13, 0xbc, 0xd8, 0xc3, 0x9, 0xf4, 0x2, 0x1b, 0x95, 0xf3, 0x72, 0x65, 0xdb, 0x6f, 0x82, 0x9e, 0x52, 0xd9, 0x89, 0xd8, 0xdf, 0x5a, 0xb0, 0x3, 0xf2, 0x9a, 0xe6, 0xef, 0x81, 0x32, 0xa5, 0x57, 0x60, 0xe0, 0xc8, 0x2d, 0x8c, 0x52, 0x63, 0x5d, 0xd8, 0xf, 0x72, 0xdf, 0xa1, 0x36, 0x1c, 0x3e, 0xc8, 0xc2, 0x4f, 0x1e, 0xfd, 0x1d, 0x11, 0xc, 0x74, 0x13, 0x21, 0x49, 0xad, 0xc0, 0xd9, 0xba, 0xda, 0xd, 0xe4, 0x6, 0x8e, 0x94, 0xe6, 0x25, 0x8b, 0xba, 0xc2, 0x2b, 0x92, 0xa, 0x90, 0xa1, 0x4a, 0x6, 0x53, 0x84, 0x79, 0xe5, 0xe7, 0xcf, 0x60, 0x74, 0xd2, 0x3b, 0x2a, 0xe0, 0x56, 0x32, 0xa6, 0x10, 0x69, 0x52, 0xf, 0xd3, 0x3d, 0x7f, 0x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, 0xf6, 0x13, 0xe, 0x83, 0x86, 0x1f, 0x3a, 0xf};
  16.  
  17. u16 values[65536] = {0};
  18. u16 values_set[65536] = {0};
  19. int values_size = 0;
  20.  
  21. int main(void) {
  22.     uint _A0F3 = 0x5d0b1c11;
  23.     const uint _A0F7 = 0x35e79125;
  24.     const uint _A0FB = 0x56596b10;
  25.     struct timespec start_time;
  26.    
  27.     for (int i = 0; i < 0x3ffffb0a; i++) {
  28.         _A0F3 = _A0F3 * _A0F7 + _A0FB;
  29.     }
  30.  
  31.     for (int i = 0; i < 0x4f6; i++) {
  32.         u16 _A10B = _A0F4;
  33.         int _A10D = _A0F5;
  34.         int _A10E = _A0F6;
  35.         int data_count = 0;
  36.         int start_index = -1;
  37.         values_size = 0;
  38.         int sublcg_count = 0;
  39.         memset(values_set, 0xff, sizeof(values_set));
  40.         while (TRUE) {
  41.             values[values_size++] = _A10B;
  42.             _A10B = (_A10B >> 1) * _A10D + _A10E;
  43.             if (values_set[_A10B] != 0xffff) {
  44.                 start_index = values_set[_A10B];
  45.                 break;
  46.             }
  47.             values_set[_A10B] = values_size;
  48.             sA567[data_count++] ^= (_A10B & 0xff);
  49.             data_count = data_count & 0x1ff;
  50.             sublcg_count++;
  51.         }
  52.         int sublcg_index = start_index;
  53.        
  54.         int period = values_size - start_index;
  55.         while ((period & 1) == 0) {
  56.             period >>= 1;
  57.         }
  58.  
  59.         int num_xors_until_repeat = period * 512;
  60.         int num_repeat_iterations = (0x1b080733 - sublcg_count) / num_xors_until_repeat;
  61.         int remaining_sublcg_iterations = (0x1b080733 - sublcg_count) % num_xors_until_repeat;
  62.         if (num_repeat_iterations & 1 == 1) {
  63.             remaining_sublcg_iterations += num_xors_until_repeat;
  64.         }
  65.  
  66.         for (int j = 0; j < remaining_sublcg_iterations; j++) {
  67.             sA567[data_count++] ^= (values[sublcg_index++] & 0xff);
  68.             data_count = data_count & 0x1ff;
  69.             if (sublcg_index >= values_size) {
  70.                 sublcg_index = start_index;
  71.             }
  72.         }
  73.         _A0F3 = _A0F3 * _A0F7 + _A0FB;
  74.         if (i % 10000 == 9999) {
  75.             struct timespec end_time;
  76.             clock_gettime(CLOCK_MONOTONIC, &end_time);
  77.             fprintf(stderr, "difftime: %f, iter: %u\n", 1000.0*end_time.tv_sec + 1e-6*end_time.tv_nsec - (1000.0*start_time.tv_sec + 1e-6*start_time.tv_nsec), i);
  78.         }
  79.     }
  80.  
  81.     for (int i = 0; i < 0x200; i++) {
  82.         printf("0x%02x, ", sA567[i]);
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top