int getMabBuf(char* fileName, char* mabBuf)
{
char sBlock[256+1];
FILE *pfFileI;
struct stat fbuf;
if(stat(fileName,&fbuf) < 0)
{
return -1;
}
if ((pfFileI = fopen(fileName, "r")) == NULL)
{
return -2;
}
while (!feof(pfFileI))
{
memset(sBlock, 0, sizeof(sBlock));
fread(sBlock, __BLOCKSIZE, 1, pfFileI);
Do_XOR(mabBuf, sBlock, __BLOCKSIZE);
}
fclose(pfFileI);
return 0;
}
void doXOR( char* deststr , char* source , int strlength )
{
int i = 0;
for( i = 0 ; i < strlength ; i++ )
{
deststr[i] ^= source[i];
}
}
#define __BLOCKSIZE 256
只是单纯的翻译代码
public class Sample {
public static final int __BLOCKSIZE = 256;
public static int getMabBuf(String fileName, byte []mabBuf) {
byte []sBlock = new byte[256+1];
File pfFile = new File(fileName);
if (! pfFile.exists()) {
return -1;
}
try (FileInputStream fis = new FileInputStream(pfFile);) {
while ((fis.read(sBlock, 0, __BLOCKSIZE)) != -1) {
doXOR(mabBuf, sBlock, __BLOCKSIZE);
Arrays.fill(sBlock, (byte)0);
}
} catch (Exception e) {
return -2;
}
return 0;
}
public static void doXOR( byte []deststr , byte []source , int strlength ) {
int i = 0;
for( i = 0 ; i < strlength ; i++ ) {
deststr[i] ^= source[i];
}
}
}