-
-
Save naf419/4184fd2c370caffd8a9430f7164e060f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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