[問題] AES 實作 in c
下面的程式是這個網頁→http://www.efgh.com/software/rijndael.htm 的部分AES實作
我用gcc rijndael.c encrypt.c -o encrypt 產生執行檔 encrypt 後
執行 encrypt 1111111111111111 aaa.txt
( encrypt password cryptofile)
卻發現一直卡在 while (!feof(stdin)) 這個loop裡
(可以一直輸入明文並按enter,但還是跑不出來)
試了很久還是沒辦法解決
麻煩大家幫我看一下 謝謝
附上AES source code (code 要自己分開):
http://www.efgh.com/software/rijndael.txt
=============================== ENCRYPT.C ===============================
#include <stdio.h>
#include "rijndael.h"
#define KEYBITS 256
int main(int argc, char **argv)
{
unsigned long rk[RKLENGTH(KEYBITS)];
unsigned char key[KEYLENGTH(KEYBITS)];
int i;
int nrounds;
char *password;
FILE *output;
if (argc < 3)
{
fputs("Missing argument\n", stderr);
return 1;
}
password = argv[1];
for (i = 0; i < sizeof(key); i++)
key[i] = *password != 0 ? *password++ : 0;
output = fopen(argv[2], "wb");
if (output == NULL)
{
fputs("File write error", stderr);
return 1;
}
nrounds = rijndaelSetupEncrypt(rk, key, 256);
/*=============卡在這個while loop裡 > <" =========================*/
while (!feof(stdin))
{
unsigned char plaintext[16];
unsigned char ciphertext[16];
int j;
for (j = 0; j < sizeof(plaintext); j++)
{
int c = getchar();
if (c == EOF)
break;
plaintext[j] = c;
}
if (j == 0)
break;
for (; j < sizeof(plaintext); j++)
plaintext[j] = ' ';
rijndaelEncrypt(rk, nrounds, plaintext, ciphertext);
if (fwrite(ciphertext, sizeof(ciphertext), 1, output) != 1)
{
fclose(output);
fputs("File write error", stderr);
return 1;
}
}
fclose(output);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.3.165
※ 編輯: zelda312 來自: 220.133.3.165 (09/02 22:14)
→
09/02 22:18, , 1F
09/02 22:18, 1F
→
09/02 22:20, , 2F
09/02 22:20, 2F
推
09/02 22:57, , 3F
09/02 22:57, 3F
→
09/02 23:44, , 4F
09/02 23:44, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章