datascience_da10
datascience_da10
Iterator<Character> it = used.iterator();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
keySquare[i][j] = it.next();
}
}
}
private String prepareText(String text) {
text = text.toUpperCase().replaceAll("J", "I").replaceAll("[^A-Z]", "");
StringBuilder prepared = new StringBuilder();
if (prepared.length() % 2 != 0) {
prepared.append('X');
}
return prepared.toString();
}
scanner.close();
}
}
import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner;
public RSAAlgorithm() {
rand = new Random();
p = BigInteger.probablePrime(bitLength / 2, rand);
q = BigInteger.probablePrime(bitLength / 2, rand);
n = p.multiply(q);
phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e = BigInteger.probablePrime(bitLength / 2, rand);
scanner.close();
}
}
scanner.close();
}
}
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
scanner.close();
}
}
8. Implement RC4 algorithm and check the following input using java
Enter plaintext : hello
Enter key of same length : yello
plaintext in bytes : 104 101 108 108 111
keystream is : 248 30 202 165 16
Cipher text is : 144 123 166 201 127
Plaintext after decryption : 104 101 108 108 111
import java.util.Scanner;
if (plaintext.length() != key.length()) {
System.out.println("Error: Key length must be the same as plaintext
length.");
scanner.close();
return;
}
scanner.close();
}
}
import java.security.*;
import java.util.Base64;
import java.util.Scanner;
scanner.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
10. Generate first five keys for the initial key : ThisIsA128BitKey in AES
algorithm using java.
sample output:
Round 0: 54684973497341313238624B657921
Round 1: 96392E2B8BDE6E8A3C5C36E5A7D441D3
Round 2: 0FEF946C7D6DBD592C019D928E72E5E1
Round 3: 27341A879D8389E63F65F2B041D4D0B3
Round 4: D0BCE5E63C05A9D2B2A5E4D73A2DFB6F
Round 5: 92E87DF5A1D457FA12F5D4BC8A374D5A
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;