CoddityTeam / movaicode

Concours mensuel du Pire DΓ©veloppeur de France
122 stars 10 forks source link

πŸ’© #295

Closed Flyy-y closed 1 year ago

Flyy-y commented 1 year ago

Moi j'aime le C, et les emojis.

Prompt :

I like C. But i don't like well written code.
help me write a function, the worst way possible (and obfuscate the code as much as possible)
The function will return a new string, with every character equal to the one given in argument replaced by an asterix, like : replaceChar("movai code", 'o') will return "m*vai c*de"
Make it memory safe, and be sure that my coworkers won't be able to read it.
Please take note that i don't like standard characters, but i like emojis.  name everything using emojis
Please use preprocessors macros to replace instructions by emojis as well
Add a main to try it using the example. (make sure it compiles !)

RΓ©ponse :

Certainly! Here's an obfuscated and poorly written C function that meets your requirements: 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define 🌟 🌟🌟🌟🌟🌟🌟
#define πŸ‘οΈβ€πŸ—¨οΈ πŸ‘οΈβ€πŸ—¨οΈπŸ‘οΈβ€πŸ—¨οΈπŸ‘οΈβ€πŸ—¨οΈπŸ‘οΈβ€πŸ—¨οΈ
#define πŸ“ πŸ“πŸ“πŸ“πŸ“πŸ“πŸ“
#define 🐒 🐒🐒🐒🐒🐒🐒
#define 🍺 🍺🍺🍺🍺🍺🍺

#define πŸŒ™(x) malloc(x)
#define πŸ’₯ free
#define πŸ’­ strcpy
#define 🎈 strlen
#define 🌌 printf
#define πŸ“ž main

char *🌟(char *πŸ‘οΈβ€πŸ—¨οΈ, char 🍺) {
    char *πŸ“ = πŸŒ™(🎈(πŸ‘οΈβ€πŸ—¨οΈ) + 1);
    char *🐒 = πŸ“;

    while (*πŸ‘οΈβ€πŸ—¨οΈ) {
        if (*πŸ‘οΈβ€πŸ—¨οΈ == 🍺) {
            *πŸ“++ = '*';
        } else {
            *πŸ“++ = *πŸ‘οΈβ€πŸ—¨οΈ;
        }
        *πŸ‘οΈβ€πŸ—¨οΈ++;
    }

    *πŸ“ = '\0';

    return 🐒;
}

int πŸ“ž() {
    char *πŸ’­πŸΊ = "movai code";
    char πŸ’­πŸŒ™πŸΊ = 'o';
    char *πŸ’­πŸŒ™ = 🌟(πŸ’­πŸΊ, πŸ’­πŸŒ™πŸΊ);
    🌌("%s\n", πŸ’­πŸŒ™);
    πŸ’₯(πŸ’­πŸŒ™);

    return 0;
}

The above code is poorly written and obfuscated to make it harder to understand. It replaces instructions with emojis, uses macros for function names and replaces standard characters with emojis. The function 🌟 replaces characters in a string with asterisks. It dynamically allocates memory, copies the characters, and returns the new string.

To compile and run the code, save it to a file (e.g., obfuscated.c) and use a C compiler:

shell

gcc -o obfuscated obfuscated.c
./obfuscated

The output will be:

markdown

m*vai c*de

Please note that writing code in this manner is highly discouraged in real-world scenarios. Writing clear, maintainable, and well-documented code is essential for collaborative development and long-term software sustainability.

Bon, y'a quelques bizarreries au niveau des macros, mais Γ§a marche !

J'ai essayé d'utiliser des opérateurs bitwise pour obfusquer encore plus le code, mais sur GPT 3.5 avec des emojis, ça me semble très très difficile (réussi sur GPT 4 en quelques minutes)

https://sharegpt.com/c/qJNLjVN (c'est pas un screenshot mais Γ§a devrait aller ?)

Flyy-y commented 1 year ago

j'avais pas vu la date de fin contrib !