Skip to content

Instantly share code, notes, and snippets.

@naf419

naf419/get_mac.c Secret

Created August 9, 2022 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naf419/4184fd2c370caffd8a9430f7164e060f to your computer and use it in GitHub Desktop.
Save naf419/4184fd2c370caffd8a9430f7164e060f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <openssl/des.h>
const int DES_BLOCKSIZE = 8;
const int HEAD_LEN = 16;
const int MAC_LEN = 6;
const int TOTAL_LEN = 24;
unsigned char KEY[] = "360028C9";
void des_ecb_decrypt(unsigned char* s, int len, unsigned char* key_buf)
{
DES_key_schedule key;
DES_set_key_unchecked((unsigned char (*)[DES_BLOCKSIZE])key_buf,&key);
int i;
for (i = 0; i < len; i+=DES_BLOCKSIZE)
DES_encrypt1((DES_LONG *)&s[i],&key,0);
}
int main(int argc, char** argv)
{
unsigned char buf[TOTAL_LEN];
read(STDIN_FILENO, buf, TOTAL_LEN);
des_ecb_decrypt(buf,HEAD_LEN,KEY);
des_ecb_decrypt(&buf[HEAD_LEN],DES_BLOCKSIZE,buf);
int i;
for (i = 0; i < MAC_LEN; i++)
printf("%02X",buf[i + HEAD_LEN]);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment