[D66] GPT: can you generate an example of obfuscated C code?

René Oudeweg roudeweg at gmail.com
Sun Dec 18 11:27:40 CET 2022


can you generate an example of obfuscated C code?

GPT:

Sure, here is an example of obfuscated C code:

#include <stdio.h>

int main() {
  int a = 1, b = 2, c = 3, d = 4;
  int e = (a + b) / (c - d);
  printf("%d\n", e);
  return 0;
}

This code includes a simple arithmetic expression that calculates the
value of e as the result of dividing the sum of a and b by the
difference of c and d. The code then prints the value of e to the
console and returns 0 to indicate that the program has completed
successfully.

To obfuscate this code, we could add unnecessary or misleading elements,
such as extra variables or unnecessary calculations, to make the code
more difficult to understand or follow. For example:

#include <stdio.h>

int main() {
  int a = 1, b = 2, c = 3, d = 4;
  int x = 5, y = 6, z = 7;
  int e = ((a + b) * x) / ((c - d) + y - z);
  printf("%d\n", e);
  return 0;
}

This version of the code includes the additional variables x, y, and z,
which are not used in the calculation of e. It also includes an extra
set of parentheses and an additional subtraction operation, which serve
no purpose other than to make the code more difficult to read and
understand. Obfuscated code like this can be used to protect
intellectual property or to make it more difficult for others to reverse
engineer or modify the code.

--

Do you know the obfuscated C contest?

GPT:

Yes, the Obfuscated C Code Contest is an annual programming competition
in which participants write C code that is difficult to understand or
follow. The goal of the contest is to create code that is still
functional and performs a specific task, but that is written in a way
that makes it difficult for others to read, understand, or modify.

Participants in the Obfuscated C Code Contest often use a variety of
techniques to make their code more difficult to understand, including
using unusual or misleading variable names, adding unnecessary or
redundant code elements, and using unconventional formatting or
indentation. The code is judged based on how well it performs its
intended task, as well as on how difficult it is to understand or follow.

The Obfuscated C Code Contest is typically held by computer science or
programming organizations, and is often intended as a fun or
lighthearted way to challenge programmers to think creatively and push
the boundaries of what is considered "normal" or "standard" coding
practice. It is not intended to be used as a serious tool for protecting
intellectual property or for any other practical purpose.


More information about the D66 mailing list