我想用Bruce Schneier的类加密文本,由Jim Conger转换为C++代码加密后,我想解密加密的文本。要尝试这一点,我正在使用它的文件。我创建了一个示例项目,但解密后的文件不包含与初始文件相同的文本。可能是什么问题?可可项目中的C++代码的Blowfish加密
以下是河豚类文件的下载link。
我在XCode中创建了Command line tool
项目,并将main.m
文件更改为main.mm
。在这里,你可以找到我的main.mm
文件的内容:
#import "blowfish.h"
#include <stdlib.h>
#include <stdio.h>
#define my_fopen(fileptr, filename, mode) \
fileptr = fopen(filename, mode); \
if (fileptr == NULL) { \
fprintf(stderr, "Error: Couldn't open %s.\n", filename); \
exit(1); \
}
const char *input_file_name = "test.txt";
const char *encoded_file_name = "encoded.txt";
const char *decoded_file_name = "decoded.txt";
unsigned char key[] = "thisisthekey";
int main(void) {
FILE *infile, *outfile;
int result, filesize;
const int n = 8; // make sure this is a multiple of 8
const int size = 1;
unsigned char input[n], output[n];
CBlowFish bf;
bf.Initialize(key, sizeof(key)-1); // subtract 1 to not count the null terminator
my_fopen(infile, input_file_name, "rb")
my_fopen(outfile, encoded_file_name, "wb")
filesize = 0;
while (result = fread(input, size, n, infile)) {
filesize += result;
fwrite(output, size, bf.Encode(input, output, result), outfile);
}
fclose(outfile);
fclose(infile);
my_fopen(infile, encoded_file_name, "rb")
my_fopen(outfile, decoded_file_name, "wb")
while (result = fread(input, size, n, infile)) {
bf.Decode(input, output, result);
fwrite(output, sizeof(output[0]), filesize < result ? filesize : result, outfile);
filesize -= result;
}
fclose(outfile);
fclose(infile);
return 0;
}
你有什么例子吗? –
@大卫请看看我的问题:http://stackoverflow.com/questions/19031842/dycrypt-value-from-blowfish-objective-c – QueueOverFlow