Question
I am trying to crack an RC4 encryption in java. I am given 8 bytes of an 11 byte key. I need to find the
I am trying to crack an RC4 encryption in java. I am given 8 bytes of an 11 byte key. I need to find the remaining 3 bytes,: Pretending I didn't have the last 3 bytes of the key, how would I change to cipher text to plain text. My test code is:
class ARC4CrackerTest {
@org.junit.jupiter.api.Test
void noHintCrack() throws NoSuchPaddingException,
NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException {
// setup the secret
byte secretBytes[] = Arrays.copyOf(ARC4Cracker.keyPrefix, 11);
secretBytes[8] = (byte) 0xd0;
secretBytes[9] = (byte) 0xff;
secretBytes[10] = 1;
SecretKey secretKey = new SecretKeySpec(secretBytes, "ARCFOUR");
// setup the cipher
// encrypt and base64 encode
String plainText = "this is the secret plain text";
String base64CipherText =
Base64.getEncoder().encodeToString(rc4Encrypt(secretKey,
plainText.getBytes()));
String base64KnownString =
Base64.getEncoder().encodeToString("secret".getBytes());
// see if the cracker can give us the answer
ARC4Cracker cracker = new ARC4Cracker();
String base64CrackedText = cracker.crack(base64CipherText,
base64KnownString);
Assertions.assertEquals(plainText, new
String(Base64.getDecoder().decode(base64CrackedText)));
}
private byte[] rc4Encrypt(SecretKey secretKey, byte[] plainText)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher arc4 = Cipher.getInstance("ARCFOUR");
arc4.init(Cipher.ENCRYPT_MODE, secretKey);
return arc4.doFinal(plainText);
}
My code for cracking is:
public class ARC4Cracker {
/**
* the know prefix. (we just need to discover the remaining 3 bytes)
*/
static public byte keyPrefix[] = { 0x13, 0x37, (byte)0xd0, 0x0d, 0x15,
0x50, (byte)0xc0, 0x01};
/**
* this method provides a hint of known plaintext, and the
corresponding cipherText
* @param base64CipherText
* @param base64PlainText base64 encoded known plain text from
* @param position the position in the stream where the text was
known
*/
public void crackedText(String base64CipherText, String
base64PlainText, int position) { }
/**
* the method will crack cipher text by searching for the correct
plain text containing
* the known string
* @param base64CipherText base64 encoded cipher text to crack
* @param base64KnownText a base64 encoded string that is know to
exist in the plain text
* @return the base64 encoded plain text or null if couldn't crack
*/
public String crack(String base64CipherText, String base64KnownText) {
return null; }
}
Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started