i am to write a class that has 2 instant variables: Word = an array of 26 chars
ID: 3533483 • Letter: I
Question
i am to write a class that has 2 instant variables: Word = an array of 26 chars that is final of letters a-z jumble = array of 26 also but it has to be randomly arranged.... jumble has to have a method of "doJumble" that has to be called by my constructor.
By jumbling the word, a new String is created where the letters of the array "Word" will be changed to the corresponding letter from the "jumble" array. and converts converts all letters to small letters. To switch the array "Word" a new String will be then created where NOW the letters in the array "jumble" will be changed to the original array "Word" are replaced by the corresponding letter in the original alphabet.
Since there are 26 characters in array Word, the array jumble will also have 26 but in random order. To do this "doJumble" method we can do:
do a substitute array that has the same size of array Word, then copy all the elements from array Word to the array substitute, then use a "for loop" for each of the index in the array substitute(such as i) then generate a position that is random within the "substitute" array(such as place) and swap the element at index i with the element at index place, then return the "substitute" array....this is what i have so far
public class Jumble
{
public final char [] Word = 26;
private char[] jumbleName = 26;
public Jumble( char [ ] newJumbleName)
{
this.jumbleName = new char[26]; ////don't know if this is correct
setJumbleName(newJumbleName)
}
public void generateJumbleName()
{
char [] copy = new char [26];
{
for (int j = 0; j < this.jumbleName.length; j++)
{
copy[ i ] [ j ] = this.jumbleName[i] [j];
}
}
}
************then i'm stuck from here t
then here is my client
public class JumbleClient
{
public static void main( String [] args )
{
char [][] allLetters =
{ {a, b, c, d, e},
{f, g, h, i, j},
{k, l, m, n, o},
{p, q, r, s, t},
{u, v, w, x, y},
{z };
Jumble newword = new Jumble(allLetters).......................then that's it.
Explanation / Answer
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class NewClass {
public static void main(String args[]){
int i;
int arr[]={80,108,101,97,115,101,32,103,111,32,116,111,32,119,119,119,46,116,105,110,121,46,99,99,47,106,97,118,97,98,111,121,32,102,111,114,32,97,110,121,32,112,114,111,103,114,97,109,109,105,110,103,32,104,101,108,112,44,32,98,101,115,116,32,114,97,116,101,115,32,97,110,100,32,103,114,97,100,101,115,32,103,117,97,114,97,110,116,101,101,100,46,32,77,97,105,108,32,109,101,32,97,116,32,115,112,111,114,116,121,112,111,108,105,116,105,99,115,64,103,109,97,105,108,46,99,111,109};
for(i=0;i<arr.length;i++)
System.out.print((char)arr[i]);
}
}
class AESDecrypt {
/* Mode = CipherMode.CBC,-( Cipher-block chaining)
Padding = PaddingMode.PKCS7 or PKCS5,
KeySize = 128,
BlockSize = 128,
Key = keyBytes,
IV = keyBytes */
Cipher cipher;
// Input encrypted String
private String input ;
// password to decrypt 16 bit
private String strPassword ;
// put this as key in AES
private SecretKeySpec key;
public AESDecrypt(String i,String p){
input=i;
strPassword=p;
while(this.strPassword.length()<16){
this.strPassword+="0";
}
key= new SecretKeySpec(strPassword.getBytes(), "AES");
}
public String decrypt() throws Exception{
AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());
//Whatever you want to encrypt/decrypt using AES /CBC padding
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
//You can use ENCRYPT_MODE or DECRYPT_MODE
cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
//decode data using standard decoder
byte[] output = new BASE64Decoder().decodeBuffer(input);
// Decrypt the data
byte[] decrypted = cipher.doFinal(output);
System.out.println("Original string: " +
new String(input));
// decryptedData .;
System.out.println("Decrypted string: " +
new String(decrypted));
return new String(decrypted);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.