Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-14-2018, 20:29
UniSoft's Avatar
UniSoft UniSoft is offline
Family
 
Join Date: May 2010
Location: Shenzhen, China
Posts: 124
Rept. Given: 24
Rept. Rcvd 259 Times in 42 Posts
Thanks Given: 25
Thanks Rcvd at 406 Times in 73 Posts
UniSoft Reputation: 200-299 UniSoft Reputation: 200-299 UniSoft Reputation: 200-299
Quote:
Originally Posted by dila View Post
The objective is to find valid 64-bit input keys that make the function return 'true'.

1. How many valid input keys are there?
A lot...

Code:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>

bool check_key(uint64_t x) {
  uint64_t r = x;
  for (size_t i = 0; i < 64; ++i) {
    for (size_t j = 0; j < 6; ++j) {
      r ^= (((x >> (1 << j)) & (i >> j) & 1) << i);
    }
  }
  return (x && r == 0);
}

uint64_t generate(void) {
  uint64_t r, x;

  do {
    x = (((uint64_t)rand() * rand()) * rand()) ^ rand();
    r = 0;
    for (size_t i = 0; i < 64; ++i) {
      for (size_t j = 0; j < 6; ++j) {
        r ^= (((x >> (1 << j)) & (i >> j) & 1) << i);
      }
    }
  } while (r == 0);
  return r;
}

int main(int argc, char *argv[])
{
    uint64_t r;
    srand((unsigned)time(NULL));

    r = generate();
    if (check_key(r))
        printf("%016llu => OK\n", r);
    else
        printf("%016llu => FAIL\n", r);

    //_getch();
    return 0;
}

Last edited by UniSoft; 01-14-2018 at 21:31.
Reply With Quote
The Following 3 Users Say Thank You to UniSoft For This Useful Post:
dila (01-14-2018), SinaDiR (01-21-2018), Stingered (01-15-2018)
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP Startup - Must be simple because I can't solve it! hobferret General Discussion 13 07-09-2005 07:44


All times are GMT +8. The time now is 00:59.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )