CSS 1 and 2
CSS 1 and 2
Source code:-
Import java.util.*;
Class ProductCipher {
// Input to be encrypted
// Enter a number
System.out.println(“Enter a number:”);
// Substitution encryption
Char c = substitutionInput.charAt(i);
substitutionOutput.append((char) (c + 5));
System.out.println(“\nSubstituted text:”);
System.out.println(substitutionOutput);
// Transposition encryption
If (modulus != 0) {
transpositionInput += “/”;
}
StringBuffer transpositionOutput = new StringBuffer();
System.out.println(“\nTransposition Matrix:”);
System.out.print©;
transpositionOutput.append©;
System.out.println();
System.out.println(transpositionOutput);
// Transposition decryption
transpositionPlaintext.append©;
// Substitution decryption
Char c = transpositionPlaintext.charAt(i);
Plaintext.append((char) (c – 5));
System.out.println(“\nPlaintext:”);
System.out.println(plaintext);
}
Output:-
Experiment No:- 02 A
Source Code:-
Import java.util.*;
Class Exp1 {
// Initializing d
Int d = 0;
Int p = sc.nextInt();
Int q = sc.nextInt();
// Calculate n
Int n = p * q;
System.out.println(“n = “ + n);
// Calculate phi(n)
Int pn = (p – 1) * (q – 1);
Int e = 0;
Search:
Int r;
Int j = I;
Int k = pn;
While (k != j) {
If (k > j) {
K = k – j;
} else {
J = j – k;
If (k == 1) {
E = I;
Break search;
System.out.println(“e = “ + e);
Go:
Int x = (e * i) % pn;
If (x == 1) {
System.out.println(“d = “ + i);
D = I;
Break go;
// Public key
System.out.println(“Enter plaintext”);
String t = sc.next();
Int m = 0;
// Summing the ASCII values of the characters in the plaintext
M += (int) t.charAt(i);
// Encryption: c = (m^e) % n
// Decryption: m = (c^d) % n
Output:-
Experiment No:- 02 B
Source Code:-
Import java.security.KeyPair;
Import java.security.KeyPairGenerator;
Import java.security.Signature;
Import sun.misc.BASE64Encoder;
Kpg.initialize(1024);
// Data to be signed
Sig.initSign(keyPair.getPrivate());
Sig.update(data);
Sig.initVerify(keyPair.getPublic());
Sig.update(data);
Output:-
Signature:
ecmcCxZyBjl4ueSJF3mULwVM9YnYHq8137X1DOxlq9KRCIUpdfQjAn75t9Gm72U
h/jzPp/wr0vSSjGINdgACyqrQc0fbAXLCBwibstPO80jEerLjJzaGfly9VZA+dCOZNpCh
ELBDD/EHMJ+RZSf0H3SUEH8/48p5EbQGDNutgAk/c