Cryptography Reference
In-Depth Information
for (int j=4;j<8;j++) if (msgroot[k][j]!=msgroot[k][j+4]) {
isCorrectRoot[k]=false;
break;
}
}
boolean correctFound=false;
for (int k=0;k<4;k++) if (isCorrectRoot[k]) {
if (!correctFound) {
correctFound=true;
ba[i]=msgroot[k];
} else {
ba[i]=null;
throw new IllegalArgumentException
(“Multiple messages satisfied redundancy requirement!”);
}
}
if (!correctFound) throw new NoSuchElementException
(“No message satisfied redundancy requirement!”);
ba[i]=removeRedundancyAndSalt(ba[i]);
}
//Go from blocks to a 1D array, and remove padding; return this
return unPad(unBlock(ba,blockSize-9),blockSize-9);
}
//Method to add redundancy and salt to blocks using Rabin
private static byte[] addRedundancyAndSalt(byte[] b,SecureRandom random) {
byte[] answer=new byte[b.length+8];
byte[] salt=new byte[4];
random.nextBytes(salt);
//Put salt in front
System.arraycopy(salt,0,answer,0,4);
//Follow with 1st 4 bytes of message-redundancy
System.arraycopy(b,0,answer,4,4);
//Copy the message over
System.arraycopy(b,0,answer,8,b.length);
return answer;
}
private static byte[] removeRedundancyAndSalt(byte[] b) {
byte[] answer=new byte[b.length-8];
//Copy the message over
System.arraycopy(b,8,answer,0,answer.length);
return answer;
}
//Other methods. . .
}
Search WWH ::




Custom Search