开源项目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 密码肯定是里面的,哪位大神帮忙看下啊 郁闷
#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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28