Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2020, 05:41
dila dila is offline
Friend
 
Join Date: Jan 2010
Posts: 60
Rept. Given: 12
Rept. Rcvd 32 Times in 14 Posts
Thanks Given: 35
Thanks Rcvd at 74 Times in 20 Posts
dila Reputation: 32
Encryption cracking challenge

Can someone help find the key?

Code:
/*
 * poly.c crackme january 2020
 * dilabox at gmail dot com
 */

#include <stdint.h>
#include <stdio.h>

uint64_t poly(uint64_t a, uint64_t b) {
  uint64_t r = 0;
  while (b) {
    r ^= a & -(b & 1);
    uint64_t m = -((a >> 63) & 1);
    a <<= 1;
    a ^= m & 0x307fdb4d20abf247;
    b >>= 1;
  }
  return r;
}

uint64_t encrypt(uint64_t data, uint64_t key) {
  data ^= key;
  uint64_t out = 1;
  for (int i = 0; i < 64; ++i) {
    if ((0x61e261e161e261e2 >> i) & 1) {
      out = poly(out, data);
    }
    data = poly(data, data);
  }
  out ^= key;
  return out;
}

uint64_t decrypt(uint64_t data, uint64_t key) {
  return encrypt(data, key);
}

int main() {
  uint64_t key = 0;
  scanf("%lx", &key);
  if (encrypt(0xe9eec16478534a39, key) == 0xf3201dcbbeefe53a) {
    printf("GOOD\n");
  } else {
    printf("BAD\n");
  }
  return 0;
}
Reply With Quote
  #2  
Old 01-12-2020, 00:33
Kurapica's Avatar
Kurapica Kurapica is offline
VIP
 
Join Date: Jun 2009
Location: Archives
Posts: 190
Rept. Given: 20
Rept. Rcvd 143 Times in 42 Posts
Thanks Given: 67
Thanks Rcvd at 404 Times in 87 Posts
Kurapica Reputation: 100-199 Kurapica Reputation: 100-199
some lines don't make sense !

uint64_t m = -((a >> 63) & 1);


how do you assign a negative value to an unsigned int64 ?
Reply With Quote
  #3  
Old 01-12-2020, 01:32
dila dila is offline
Friend
 
Join Date: Jan 2010
Posts: 60
Rept. Given: 12
Rept. Rcvd 32 Times in 14 Posts
Thanks Given: 35
Thanks Rcvd at 74 Times in 20 Posts
dila Reputation: 32
-x is the same as ~x + 1

In this case the code is extracting the most-significant bit (MSB) from a and then creating a 64-bit mask from it.

If MSB(a) == 0, the result is 0x0000000000000000
Otherwise, if MSB(a) == 1, the result is 0xFFFFFFFFFFFFFFFF
Reply With Quote
  #4  
Old 01-12-2020, 08:58
chants chants is offline
VIP
 
Join Date: Jul 2016
Posts: 725
Rept. Given: 35
Rept. Rcvd 48 Times in 30 Posts
Thanks Given: 666
Thanks Rcvd at 1,050 Times in 475 Posts
chants Reputation: 48
Some compilers might warn or even generate an error over that. But as said it's just a 2s compliment and the sign but is merely interpreted differently as a cast occurred to signed and back to unsigned. This challenge is interesting need to look for a crypto weakness in the inner function perhaps. Brute force won't work with 2^64...
Reply With Quote
The Following User Says Thank You to chants For This Useful Post:
niculaita (01-14-2020)
Reply

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
The Mutilated AES Challenge dila General Discussion 2 08-27-2018 04:06
Cracking App come with Challenge Code new air General Discussion 2 08-19-2003 00:49


All times are GMT +8. The time now is 12:35.


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