Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*****JAVA through careful research our fellow spies have found that the vain elite key master of the enemy starts all of the encryption keys with

*****JAVA

through careful research our fellow spies have found that the vain elite key master of the enemy starts all of the encryption keys with 0x1337d00d1550c001. we also know that all keys are 11 bytes long.

you are to implement the ARC4Cracker class found in ARC4Cracker.javaimage text in transcribed . (please do not change the package name, class name, or method signatures of that class.) when we have a message to crack we will instantiate an ARC4Cracker and call the crack(...) method. if we have partially cracked other messages with the same key, we will call crackedText(...) for each partially cracked message before calling crack(...) . this may sometimes help you in your cracking.

you can use the test cases in ARC4CrackerTest.javaimage text in transcribed to aid you in your task. you can modify them and add to them. you do not need to submit the tests.

ARC4Cracker.java

package

/**

* cracks weakened ARC4 keys. we know all cipher text has been encrypted

with

* a 11 byte ARC4 key. we also know that the first 8 bytes of the key

are:

* 0x1337d00d1550c001

*

* each instance of this class represents a ARC4 key to be discovered.

all hints

* about cracked text and requests to crack will be for cipher text

encrypted

* with the same key.

*/

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; }

}

*****************TEST CASE *************

import org.junit.jupiter.api.Assertions;

import javax.crypto.BadPaddingException;

import javax.crypto.Cipher;

import javax.crypto.IllegalBlockSizeException;

import javax.crypto.NoSuchPaddingException;

import javax.crypto.SecretKey;

import javax.crypto.spec.SecretKeySpec;

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

import java.util.Arrays;

import java.util.Base64;

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);

}

@org.junit.jupiter.api.Test

void hintedCrack() throws NoSuchPaddingException,

NoSuchAlgorithmException, InvalidKeyException, BadPaddingException,

IllegalBlockSizeException {

// setup the secret

byte secretBytes[] = Arrays.copyOf(ARC4Cracker.keyPrefix, 11);

secretBytes[8] = (byte) 0xbe;

secretBytes[9] = (byte) 0xef;

secretBytes[10] = 2;

SecretKey secretKey = new SecretKeySpec(secretBytes, "ARCFOUR");

ARC4Cracker cracker = new ARC4Cracker();

byte plainHint1[] = "the hint that only the last part was

broken".getBytes();

byte cipherHint1[] = rc4Encrypt(secretKey, plainHint1);

cracker.crackedText(Base64.getEncoder().encodeToString(Arrays.copy

OfRange(cipherHint1, 10, 30)),

Base64.getEncoder().encodeToString(Arrays.copyOfRange(plai

nHint1, 10, 30)), 10);

byte plainHint2[] = "we figured out this message".getBytes();

byte cipherHint2[] = rc4Encrypt(secretKey, plainHint2);

cracker.crackedText(Base64.getEncoder().encodeToString(Arrays.copy

OfRange(cipherHint2, 0, 15)),

Base64.getEncoder().encodeToString(Arrays.copyOfRange(plai

nHint2, 0, 15)), 0);

// encrypt and base64 encode

String plainText = "this is the secret with hints";

String base64CipherText =

Base64.getEncoder().encodeToString(rc4Encrypt(secretKey,

plainText.getBytes()));

String base64KnownString =

Base64.getEncoder().encodeToString("hint".getBytes());

// see if the cracker can give us the answer

String base64CrackedText = cracker.crack(base64CipherText,

base64KnownString);

Assertions.assertEquals(plainText, new

String(Base64.getDecoder().decode(base64CrackedText)));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

unimolecular deacy topic from chemical kinetics please help me

Answered: 1 week ago