• Redkey@programming.dev
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    2 months ago

    I don’t know if this will work or even compile, but I feel like I’m pretty close.

    long main () {
        char output;
        unsigned char shift;
        long temp;
        
        if (i < 152) {
            shift = (i & 1) * 7;
            temp = b[i >> 1] >> shift;
            i++;
            output = (char)(64 & temp);
            output += (char)((n >> (temp & 63)) & main());
            printf("%c", output);
        }
    
        return 63;
    }
    
    • ulterno@lemmy.kde.social
      link
      fedilink
      English
      arrow-up
      9
      ·
      2 months ago

      Here’s it with some amount of de-obfuscation:

      #include <stdio.h>
      short i = 0;
      const long b[]
      	= { 0xd60,  0x3200,  0x1ca8, 0x74e2, 0x9c,   0x66e8, 0x5100,  0x14500,
      		0x63b8, 0x49c6,  0xe0,   0x6200, 0x75e8, 0x57a6, 0xe8,    0x4300,
      		0x4500, 0x63b8,  0x49ea, 0xc6,   0x548e, 0x22,   0x75e8,  0x57a6,
      		0xc6,   0x2fae,  0x7486, 0x8a,   0xd72,  0x4f9c, 0x63c6,  0x4ea2,
      		0x809c, 0x66e8,  0x5100, 0x5c00, 0x71a2, 0x51b8, 0x4e9e,  0xc6,
      		0x6200, 0x70c4,  0x8022, 0x7d00, 0x439c, 0x63b8, 0x6ae0,  0x54c0,
      		0x47e8, 0xe2,    0x5192, 0x6fc4, 0x4900, 0x60e8, 0x100ca, 0x14fe8,
      		0x6000, 0x44e92, 0x6300, 0x57c4, 0xae,   0x4ecc, 0x62de,  0xc6,
      		0xafae, 0x70c4,  0x9e,   0x4ec6, 0x639c, 0x5100, 0x4ecc,  0x74a2,
      		0x9e,   0x54e8,  0x7100, 0x608a };
      const long n = 9147811012615426336;
      long
      main ()
      {
      	if (i < 152)
      	{
      		char shifter;
      		if (i % 2 == 0)
      		{
      			shifter = 8;
      		}
      		else
      		{
      			shifter = 1;
      		}
      		char adder1 = (b[i >> 1] >> shifter) & 64;
      
      		char adder2 = (n >> (b[i >> 1] >> shifter)) & 63;
      
      		char to_print = (char)adder1 + adder2;
      		i++;
      		main ();
      		printf ("%c", to_print);
      	}
      	return 63;
      }
      

      Needless to say, the return value doesn’t matter any more. So you can change it to 0 or 69 depending upon your preferences.

      • ulterno@lemmy.kde.social
        link
        fedilink
        English
        arrow-up
        5
        ·
        2 months ago

        And more de-obf:

        #include <stdio.h>
        
        const char addarr1[]
        	= { 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40,
        		0x0,  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x0,
        		0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x0,  0x40,
        		0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x0,  0x40,
        		0x40, 0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
        		0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x0,  0x0,  0x40, 0x40, 0x0,  0x40,
        		0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x0,  0x40,
        		0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x0,  0x0,
        		0x40, 0x0,  0x40, 0x40, 0x40, 0x0,  0x40, 0x0,  0x40, 0x40, 0x40, 0x40,
        		0x0,  0x0,  0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x0,  0x40,
        		0x0,  0x40, 0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x40, 0x0,
        		0x40, 0x40, 0x40, 0x40, 0x0,  0x40, 0x0,  0x40, 0x40, 0x40, 0x40, 0x0,
        		0x40, 0x40, 0x40, 0x0,  0x0,  0x0,  0x0,  0x0 };
        
        const char addarr2[]
        	= { 0x9,  0x26, 0x20, 0x39, 0x2f, 0x35, 0x32, 0x20, 0x2c, 0x2f, 0x36, 0x25,
        		0x20, 0x2c, 0x25, 0x34, 0x34, 0x25, 0x32, 0x20, 0x29, 0x33, 0x2e, 0x27,
        		0x34, 0x20, 0x27, 0x29, 0x36, 0x25, 0x2e, 0x20, 0x29, 0x2e, 0x20, 0x34,
        		0x28, 0x25, 0x20, 0x26, 0x2f, 0x32, 0x2d, 0x20, 0x2f, 0x26, 0x20, 0x28,
        		0x29, 0x27, 0x28, 0x2c, 0x39, 0x20, 0x2f, 0x22, 0x26, 0x35, 0x33, 0x23,
        		0x21, 0x34, 0x25, 0x24, 0x20, 0x3,  0x2c, 0x20, 0x29, 0x33, 0x20, 0x29,
        		0x34, 0x20, 0x32, 0x25, 0x21, 0x2c, 0x2c, 0x39, 0x20, 0x21, 0x20, 0x2c,
        		0x2f, 0x36, 0x25, 0x20, 0x2c, 0x25, 0x34, 0x34, 0x25, 0x32, 0x3f, 0xa,
        		0x9,  0x20, 0x24, 0x2f, 0x2e, 0x27, 0x34, 0x20, 0x2b, 0x2e, 0x2f, 0x37,
        		0x2c, 0x20, 0x22, 0x35, 0x34, 0x20, 0x37, 0x28, 0x21, 0x34, 0x20, 0x9,
        		0x20, 0x24, 0x2f, 0x20, 0x2b, 0x2e, 0x2f, 0x37, 0x20, 0x29, 0x33, 0x20,
        		0x34, 0x28, 0x21, 0x34, 0x20, 0x9,  0x20, 0x2c, 0x2f, 0x36, 0x25, 0x20,
        		0x39, 0x2f, 0x35, 0x21, 0x20, 0x3c, 0x33, 0xa };
        
        int main ()
        {
        	for (int i = 0; i < 152; i++)
        	{
        		char adder1 = addarr1[i];
        
        		char adder2 = addarr2[i];
        
        		char to_print = (char)adder1 + adder2;
        
        		printf ("%c", to_print);
        	}
        	return 63;
        }
        
        

        I guess I should have kept the recursion and straightened it out in the next step, but now that it’s done…

        The next step will just have an array of the characters that would be printed, so I’ll leave it here.

    • ulterno@lemmy.kde.social
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 months ago

      Some kind of Caesar cipher you made?

      fIy uo rolevl teet rsi’n tigev nnit ehf ro mfoh gilh yboufcstadeC ,sii terlayla l vo eelttre ? Iod’n tnkwo ,ub thwtaI d onkwoi shttaI l vo eoy!u< 3%

      • Redkey@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        2 months ago

        Whoops! When I looked at the second time that the shift value is calculated, I wondered if it would be inverted from the first time, but for some reason I decided that it wouldn’t be. But looking at it again it’s clear now that (1 - i) = (-i + 1) = ((~i + 1) + 1), making bit 0 the inverse. Then I wondered why there wasn’t more corruption and realized that the author’s compiler must perform postfix increments and decrements immediately after the variable is used, so the initial shift is also inverted. That’s why the character pairs are flipped, but they still decode correctly otherwise. I hope this version works better:

        long main () {
            char output;
            unsigned char shift;
            long temp;
            
            if (i < 152) {
                shift = (~i & 1) * 7;
                temp = b[i >> 1] >> shift;
                i++;
                output = (char)(64 & temp);
                output += (char)((n >> (temp & 63)) & main());
                printf("%c", output);
            }
        
            return 63;
        }
        

        EDIT: I just got a chance to compile it and it does work.