/ analysis / sbt.c
sbt.c
 1  // run with gcc -Wall -g -o sbt ../sbt.c sbt.c && ./sbt
 2  #include <stdint.h>
 3  #include <string.h>
 4  #include <stdio.h>
 5  #include <stdarg.h>
 6  #include "../sbt.h"
 7  
 8  void dump(const uint8_t *p, const size_t len, const char* msg, ...) {
 9    va_list args;
10    va_start(args, msg);
11    vfprintf(stderr,msg, args);
12    va_end(args);
13    fprintf(stderr," ");
14    for(size_t i=0;i<len;i++)
15      fprintf(stderr,"%02x", p[i]);
16    fprintf(stderr,"\n");
17  }
18  
19  //static void key_id(sbt_ctx *ctx) {
20  //  printf("key_id: ");
21  //  for(int i=7;i>0;i-=2) {
22  //    putchar((((ctx->cipherblock[i]>>4^ctx->cipherblock[i-1]) & 0xf) | 0x40) + 1);
23  //  }
24  //  printf("\n");
25  //}
26  
27  int main(void) {
28    //uint8_t fixed_fill[8] = { 0xf5, 0xc0, 0x7a, 0x10, 0x8a, 0xaf, 0x17, 0xcf };
29    //memcpy(cipherblock, fixed_fill, 8); // 1cbf, 1cc4
30    //memcpy(state, cipherblock, 8);
31    //memcpy(ctrlvar, cipherblock, 7);
32    //sbt();
33    //dump(state, sizeof state, "state");
34    //dump(ctrlvar, sizeof ctrlvar, "ctrlvar");
35    //return 0;
36  
37    const uint8_t __attribute__((nonstring)) key[15]="\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01";
38    // is not necessary - but nice to have
39    //set_key(key);
40    //key_id();
41  
42    //dump(cipherblock, sizeof cipherblock, "cipherblock");
43    // navelpluis
44    //const uint8_t ct[]="LEEIC BIIKY DBCFE DPKLB ECILE\xfe";
45                       //"JDMNJ AEJHP CPBLO JPJDD BEDNG\xfe"
46    // hello world
47    //const uint8_t ct[]="BAMLK GAFFJ EOBCP EEIMP CDAFP\xfe";
48    //const uint8_t ct[]="HMBGL MMAEG OILPM LBCHE NCAFJ\xfe";
49    //const uint8_t ct[]="HMMHI EAPIO OGBBI HLOPI GGIEK\xfe";
50    // other msg
51    //const uint8_t ct[]="FBFDN MLBPE IJCFF DKDJB LFNNP DMCOM LBMKM GGOKL IJHCO JOEDE LFCCK PIHDP MMHCB DJGNE CGOCL NCAAB JJAIC GPJCH GHBNP FDKNA MGJHP NICPF\xfe";
52    const uint8_t __attribute__((nonstring)) ct[]="GDMIG BGAMF HIGIK ACDGJ GGJOL\xfe";
53  
54    uint8_t ctx[sizeof ct-1]={0};
55    int i;
56    for(i=0;ct[i]!=0xfe;i++) {
57      ctx[i]=(ct[i] & 0x3f);
58    }
59    ctx[i]=ct[i];
60    //dump(ctx, sizeof ctx, "ctx");
61    sbt_decrypt(ctx, key);
62    printf("\n");
63  
64    //const uint8_t plaintext[]="HELLO WORLD\xfe";
65    //uint8_t ptx[sizeof plaintext-1]={0};
66    //uint8_t out[((sizeof(ptx) / 3) + 1) * 6 + 6 + 1]={0};
67    //for(i=0;plaintext[i]!=0xfe;i++) {
68    //  ptx[i]=(plaintext[i] & 0x3f);
69    //}
70    //ptx[i]=plaintext[i];
71    //encrypt(ptx, key, out);
72    //printf("%s\n",out);
73  
74    //uint8_t k2[15]="CRYPTOMUSEUMSBT";
75    //for(int i=0;i<15;i++) k2[i]&=0x3f;
76    //uint8_t pt[]="YOU GUYS ROCK. THIS IS SO MUCH FUN, THANK YOU -- S 2023-12-07\xfe";
77    //uint8_t output[((sizeof(pt) / 3) + 1) * 6 + 6 + 1]={0};
78    //for(i=0;pt[i]!=0xfe;i++) pt[i]&=0x3f;
79    //encrypt(pt, key, output);
80    //printf("%s\n",output);
81  
82    return 0;
83  }