• ulterno@lemmy.kde.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 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
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      3 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.