在Java中,>>是什么或<<意思?

时间:2015-04-04 17:45:34

标签: java

自从我用Java做了一些事情以来已经有几年了。但我试图从头开始编写一个计算S-DES加密和解密的程序。我正在网上查看当前的代码,只是为了帮助我们设置我的程序。但我不确定原作者试图做什么......

以下是代码的一部分..关于它不是我的,&我没有复制它,我只是想了解他们在这里做了什么?

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;

}

1 个答案:

答案 0 :(得分:1)

&LT;&LT;二进制左移运算符。左操作数值向左移动右操作数指定的位数 A&lt;&lt; 2将给出240这是1111 0000
  二进制右移运算符&gt;。左操作数值向右移动右操作数指定的位数。
A&gt;&gt; 2将给出15这是1111