以下が平文です.
NASA debuted a color picture from the Spirit rover
on Tuesday showing gray rocks peppering a Martian
lake bed awash in its natural hues of red pink
and orange Mission scientists said they were
bowled over by the spectacular quality of
the image taken with a dual camera system
called pancam that is mounted on a mast jutting
up from the rover I think my reaction has been
one of shock and awe said Jim Bell the team
member in charge of pancam Using special software
mission scientists can fly though the image zooming
in on rocks and other landscape features of interest
It is approximately the color that you would see
with your eyes if you were standing there Bell said
The resolution of course is pretty much what you
would see Pancam has 20 20 vision It is three to
four times better than any previous mission that has gone
to Mars in fact these pictures are the highest resolution
highest detailed pictures of Mars ever obtained They
are absolutely spectacular
この平文を行数4,列数8で矩形転置で暗号化したいのですが,最後のabsolutely spectacularのbsolutely spectacularの部分が暗号化されません.
平文の末尾に到達した場合は,矩形の残りの部分にスペースが入った状態にしてから暗号文を取り出して終了するようにしたいです.
以下が現在のコードです.どこを直せばいいのか教えてください.よろしくお願いします.
コード:
#include <iostream>
#include <fstream>
using namespace std;
#define M 4
#define N 8
void main() {
ifstream inFile;
ofstream outFile;
char buffer[M][N];
int row = 0;
int col = 0;
inFile.open("plain.txt");
outFile.open("crypt.txt");
char ch = inFile.get();
while (!inFile.eof()) {
buffer[row][col] = ch;
col++;
if (col == N) {
col = 0;
row++;
}
ch = inFile.get();
if (row == M) {
for (int j = 0; j < N; j++) {
for (int i = 0; i < M; i++) {
outFile << buffer[i][j];
buffer[i][j] = 0;
}
col = 0;
row = 0;
}
}
}
inFile.close();
outFile.close();
}