-5
自從我用Java做了什麼以來,這已經過去了幾年。但我正試圖編寫一個計算S-DES加密和解密的程序。我在網上查看當前的代碼,只是爲了幫助我設置我的程序。但我不知道原作者是試圖做...在Java中,>>或<<是什麼意思?
這裏是一塊code..again的它不是我的,&我不是複製它,我只是想明白他們在這裏做什麼?
public class SDESProject {
public static void main(String args[]) throws Exception
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please Enter the 10 Bit Key :");
int K = Integer.parseInt(keyboard.nextLine(),2);
SDES A = new SDES(K);
System.out.println("Enter the 8 Bit Plaintext : ");
int m = Integer.parseInt(keyboard.nextLine(),2);
System.out.print("\nKey K1: ");
SDES.printData(A.K1, 8);
System.out.print("\nKey K2: ");
SDES.printData(A.K2, 8);
m = A.encrypt(m);
System.out.print("\nEncrypted Message: ");
SDES.printData(m, 8);
m = A.decrypt(m);
System.out.print("\nDecrypted Message: ");
SDES.printData(m, 8);
keyboard.close();
}
}
class SDES
{
public int K1, K2;
public static final int P10[] = { 3, 5, 2, 7, 4, 10, 1, 9, 8, 6};
public static final int P10max = 10;
public static final int P8[] = { 6, 3, 7, 4, 8, 5, 10, 9};
public static final int P8max = 10;
public static final int P4[] = { 2, 4, 3, 1};
public static final int P4max = 4;
public static final int IP[] = { 2, 6, 3, 1, 4, 8, 5, 7};
public static final int IPmax = 8;
public static final int IPI[] = { 4, 1, 3, 5, 7, 2, 8, 6};
public static final int IPImax = 8;
public static final int EP[] = { 4, 1, 2, 3, 2, 3, 4, 1};
public static final int EPmax = 4;
public static final int S0[][] = {{ 1, 0, 3, 2},{ 3, 2, 1, 0},{ 0, 2, 1,
3},{ 3, 1, 3, 2}};
public static final int S1[][] = {{ 0, 1, 2, 3},{ 2, 0, 1, 3},{ 3, 0, 1,
2},{ 2, 1, 0, 3}};
public static int permute(int x, int p[], int pmax)
{
int y = 0;
for(int i = 0; i < p.length; ++i)
{
y <<= 1;
y |= (x >> (pmax - p[i])) & 1;
}
return y;
}
public static int F(int R, int K)
{
int t = permute(R, EP, EPmax)^K;
int t0 = (t >> 4) & 0xF;
int t1 = t & 0xF;
t0 = S0[ ((t0 & 0x8) >> 2) | (t0 & 1) ][ (t0 >> 1) & 0x3 ];
t1 = S1[ ((t1 & 0x8) >> 2) | (t1 & 1) ][ (t1 >> 1) & 0x3 ];
t = permute((t0 << 2) | t1, P4, P4max);
return t;
}
請參閱java中的移位運算符 - https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html – Razib 2015-04-04 17:50:01