Recall, if you do the Modes.java assignment, you are creating various static methods that act on StringBuffers. Let me explain how everything is supposed to plug in. Suppose that you have created an RSA Kernel that: 1) Doesn't try to pad 2) Assumes that BOTH plain and cipher text are given as hexadecimal ascii, with no whitespace -and now blocksizes are TWICE as big!!! NOTE: (2) is a new assumption, but it makes life a little easier. ------------DISCUSSION OF HOW TO ACHIEVE CONDITION (2)--------- Requirement (2) is not hard to achieve. Suppose you had code in a file called RSAnoPads.java which didn't try to pad and converted ASCII to BigInteger upon encryption (as I suggested). ----SUB-DISCUSSION: WHAT ORIGINAL RSA DID---- Recall that when the ASCII blocks are converted into BigIntegers the following procedure is used on each block. Suppose a block of size 64 looked like: c1, c2, c3, .... , c64 where c1 is the first char, c2 is the second char, etc. What happens next is that we convert the unicode char's into bytes (this is done using the getBytes() method of the String class. So now we have bytes: b1, b2, b3, .... , b64 or as an array: b[0], b[1], ... , b[63] This is almost good enough to plug into BigInteger. But we want to make sure we have a non-negative integer that is smaller than the number N = product of two primes. Assumming that N has exactly 8*64 significant bits (guys: when picking your primes, MAKE SURE THIS HAPPENS IN YOUR RSA CODE!!! If you pick two random 8*32 bit primes, than you have better than 35% chance that their product will have exactly 8*64 significant bits, so you don't have to search too long to get N = p1 * p2 of the required length) ... back to the discussion... assuming that N has exactly 8*64 significant bits, and since we want to make sure the block is represented as a number in the range [0,N-1] the easiest way to insure this is to set the most significant bit of b1 to 0 with the code b[0] &= (byte)127 with is the bitwize "and" of b[0] with the byte 01111111 Now what happened what that you feed the bytes into the BigInteger constructor, which automatically glues the bytes together into a very long integer. --------------BACK TO DISCUSSING CONDITION (2): BUT: BigInteger, also has a constructor that takes hexadecimal strings. Thus, upon encryption, we would have a bunch of hexadecimal digits that looked like: h1, h2, h3, .... , h128 (remember, blockas are TWICE as big) Again, just-in-case, you should make sure the most significant digit creates a number with less bits than N = p1*p2. If h1 is in the range [0,7] you're fine. But if h1 is in the range [8,15], we have a problem, and should reset with a command such as: h1 -= 8 to retain all the other bits (you can't do this exactly since we're dealing with a part of a StringBuffer but you get the idea...) Now if the text was actually originally 7-bit ASCII, all this discussion about h-=8 (and also b[0] &= (byte)127) are moot and the code would work just as well. But just in case........include the code. THE POINT???????? 1) You should convert bytes to hex in an UNSIGNED fashion. The easiest way to do this is to cheat and use the code in BigInteger. So a conversion of a single block would look like: String bytes2hex(String bstr, int blockSize){ byte[] b = bstr.getBytes(); b[0] &= (byte)127; String h = (new BigInteger(b)).toString(16); //base-26 //finally, create and return correct size blocks if( h.length() <= blockSize){ int zeroslength = blockSize - h.length(); String leadingZeros = ""; for(int i=0; i