Crypto Codes
Crypto Codes
int n = 3;
int[][] keyMatrix = new int[n][n];
k = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1; j++) {
int temp = plainText.charAt(k) - 65;
plainTextMatrix[i][j] = temp;
k += 1;
System.out.println(temp);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1; j++) {
System.out.print(plainTextMatrix[i][j] + " ");
}
}
int[][] matrix = new int[3][1];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 1; j++) {
matrix[i][j] = 0;
for (int z = 0; z < 3; z++) {
matrix[i][j] += (keyMatrix[i][z] *
plainTextMatrix[z][j]);
}
matrix[i][j] = matrix[i][j] % 26;
}
}
String result = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1; j++) {
result += alphabets[matrix[i][j]];
}
}
System.out.println(result);
}
}
SHA512
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
byte[] MessageDigest =
md.digest(plainText.getBytes());
return cipherText;
} catch (NoSuchAlgorithmException e) {
System.err.println(e);
return "";
}
}
}
MD5
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
byte[] MessageDigest =
md.digest(plainText.getBytes());
}
}
Diffie hellman
P = 23;
G = 9;
a = 4;
b = 3;
x = power(G, a, P);
y = power(G, b, P);
ka = power(y, a, P);
kb = power(x, b, P);
p = 13;
g = 2;
d = 3;
e = power(g, d, p);
m = 4;
k = 7;
y1 = power(g, k, p);
y2 = (m * power(e, k, p)) % p;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
byte[] encrypted =
cipher.doFinal(data.getBytes());
System.out.println(new String(encrypted));
} catch (Exception e) {
System.out.println(e);
}
}
}
DES
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;