+ -
当前位置:首页 → 问答吧 → 开源项目rexlog希望有熟悉css的朋友帮忙开发

开源项目rexlog希望有熟悉css的朋友帮忙开发

时间:2011-10-14

来源:互联网

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <openssl/evp.h>

#define MAX_LINE 100

FILE *words;
FILE *some;
FILE *aes_128_cbc;

char plain_text[1024];
char cipher_text[1024];
unsigned char key[1024];
const unsigned char iv[] = {0,0,0,0,0,0,0,0};

void compare(char *e_text);
int do_encrypt(char *text);
void decrypt_cipher_text();

void compare(char *e_text){
if((some = fopen("/home/neo/cw1/task5/some", "rb")) == NULL){
perror("can not open file!\n");
exit(1);
}
while((fgets(plain_text, MAX_LINE, some)) != NULL){
printf("%s", plain_text);
if(strcmp(plain_text, e_text) == 0){
printf("the right key is %s", key);
}
/*else{
printf("the encryption text is %s", e_text);
printf("the wrong key is %s", key);
}*/
}
fclose(some);
}

int do_decrypt(char *text){

unsigned char outbuf[1024];
int outlen, tmplen;
EVP_CIPHER_CTX ctx;

if((words = fopen("/home/neo/cw1/task5/words.txt", "rb")) == NULL){
perror("can not open file!\n");
exit(1);
}

while((fgets(key, MAX_LINE, words)) != NULL){
EVP_CIPHER_CTX_init(&ctx);
printf("current word is %s\n", key);
EVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, iv);
if(!EVP_DecryptUpdate(&ctx, outbuf, &outlen, text, strlen(text))){
return 1;
}
if(!EVP_DecryptFinal_ex(&ctx, outbuf + outlen, &tmplen)){
return 1;
}
outlen += tmplen;
//EVP_CIPHER_CTX_cleanup(&ctx);
printf("the decrpt text is %s\n", outbuf);
//break;
compare(outbuf);
}
fclose(words);
return 0;

}

void decrypt_cipher_text(){

int r;
if((aes_128_cbc = fopen("/home/neo/cw1/task5/some.aes-128-cbc", "r")) == NULL){
perror("can not open file!\n");
exit(1);
}

while((fgets(cipher_text, MAX_LINE, aes_128_cbc)) != NULL){
printf("%s\n", cipher_text);
r = do_decrypt(cipher_text);
if(r == 0){
printf("failed");
}
else if(r == 1){
printf("successful");
}

}

fclose(aes_128_cbc);

}

int main(){
decrypt_cipher_text();
return 0;
}
一直不知道错在哪里。。。就是找不出key是什么。。。老师给了个字典words.txt 密码肯定是里面的,哪位大神帮忙看下啊 郁闷

作者: Libertus   发布时间: 2011-10-14

热门下载

更多