I'm developing a system that calculate the encryption time of method using different keys. the time works fine using the keys 128 and 192. but not the key 256. the output of the time using key 256 it shows as key 128-bit. this is part of the source code for the key method, because i think in the source code of the key there is something that make the system doesn't take the key 256-bit, i tried downloading the jce files:
private static int[] expandKey(byte[] key){
int n = key.length/4;
int[] tmp = new int[40];
int[] data = new int[n];
for(int i =0;i<data.length;i++)
data[i] = 0;
int off = 0;
for(int i=0;i<data.length;i++){
data[i] = ((key[off++]&0xff))|
((key[off++]&0xff) << 8) |
((key[off++]&0xff) << 16) |
((key[off++]&0xff) << 24);
}
int[] T = new int[15];
for(int i=0;i<T.length;i++){
if(i<data.length) T[i] = data[i];
else if(i == data.length) T[i] = n;
else T[i] = 0;
}
for(int j=0;j<4;j++){
for(int i=0;i<T.length;i++)
T[i] = T[i] ^ (rotl(T[Math.abs(i-7 %15)] ^ T[Math.abs(i-2 %15)],3) ^ (4*i+j));
for(int c=0;c<4;c++)
for(int i=0;i<T.length;i++)
T[i] = T[i] + rotl(s_box[(int). (T[Math.abs(i-1%15)] & 0x000001ff)],9);
for(int i = 0;i<=9;i++) tmp[10*j+i] = T[4*i%15];
}
int[] B = {0xa4a8d57b, 0x5b5d193b, 0xc8a8309b, 0x73f9a978};
int j,w,m,r,p;
for(int i = 5;i<=35;i++){
j = tmp[i] & 0x00000003;
w = tmp[i] | 0x00000003;
m = generateMask(w);
r = tmp[i-1] & 0x0000001f;
p = rotl(B[j],r);
tmp[i] = w ^ (p & m);
}
return tmp;
}
private static int generateMask(int x){
int m;
m = (~x ^ (x>>>1)) & 0x7fffffff;
m &= (m >> 1) & (m >> 2);
m &= (m >> 3) & (m >> 6);
if(m == 0)
return 0;
m <<= 1; m |= (m << 1); m |= (m << 2); m |= (m << 4);
m |= (m << 1) & ~x & 0x80000000;
return m & 0xfffffffc;
}
this is the code:
byte[] plain = plaintext.getText().getBytes();
byte[] K = key.getText().getBytes();
long startTime = System.currentTimeMillis();
byte[] encrypted = encrypt(plain, K);
String a = bytesToHex(encrypted);
encryptedtext.setText(a);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
time.append(Integer.toString((int) elapsedTime) + " ms \n");
User contributions licensed under CC BY-SA 3.0