Crypto Notes Vit
Crypto Notes Vit
Digital Assignment – 2
CODE;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Scanner;
return;
// Display Round 1 key (Just showing input key as DES generates subkeys internally)
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
if (plainTextHex.equals("0002000000000001") &&
keyHex.equals("0002000000000002")) {
} else {
scanner.close();
+ Character.digit(s.charAt(i+1), 16));
return data;
sb.append(String.format("%02X", b));
return sb.toString();
CODE:
import java.util.Scanner;
{0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4,
0x72,
0xC0},
{0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8,
0x31, 0x15},
{0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27,
0xB2, 0x75}
};
};
return result;
return result;
return result;
int result = 0;
while (b > 0) {
if ((b & 1) != 0) {
result ^= a;
a <<= 1;
if (highBitSet) {
a ^= 0x1B;
b >>= 1;
}
return result & 0xFF;
result[row][col] =
gmul(MIX_COLUMNS_MATRIX[row][0], state[0][col]) ^
gmul(MIX_COLUMNS_MATRIX[row][1], state[1][col]) ^
gmul(MIX_COLUMNS_MATRIX[row][2], state[2][col]) ^
gmul(MIX_COLUMNS_MATRIX[row][3], state[3][col]);
return result;
return matrix;
System.out.println();
}
System.out.println();
printMatrix(state);
// Step 2: SubBytes
state = subBytes(state);
printMatrix(state);
// Step 3: ShiftRows
state = shiftRows(state);
printMatrix(state);
// Step 4: MixColumns
state = mixColumns(state);
System.out.println("\nState after MixColumns:");
printMatrix(state);
printMatrix(state);
CODE:
import java.util.Arrays;
import java.util.Scanner;
private int[] S;
private int x, y;
this.stateSize = stateSize;
S = new int[stateSize];
x = y = 0;
keyScheduling(key);
S[i] = i;
int j = 0;
swap(i, j);
S[i] = S[j];
S[j] = temp;
return result;
x = (x + 1) % stateSize;
y = (y + S[x]) % stateSize;
swap(x, y);
scanner.nextLine();
key[i] = scanner.nextInt();
scanner.nextLine();
plaintext[i] = scanner.nextInt();
scanner.close();
}
CODE AND OUTPUT SCREENSHOT:
EXPERIMENT NOTEBOOK: