In Java what does >> or << mean? -
In Java what does >> or << mean? -
this question has reply here:
java “bit shifting” tutorial? [closed] 8 answersits been few years since have done java. trying write programme scratch calculates s-des encryption , decryption. looking @ current code online aide on how set program. not sure original author trying do...
here piece of code..again its not mine, & i'm not copying it, i'm trying understand doing here?
public class sdesproject { public static void main( string args[]) throws exception { scanner keyboard = new scanner(system.in); system.out.println("please come in 10 bit key :"); int k = integer.parseint(keyboard.nextline(),2); sdes = new sdes( k); system.out.println("enter 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 = 0; < p.length; ++i) { y <<= 1; y |= (x >> (pmax - p[i])) & 1; } homecoming 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); homecoming t; }
<< binary left shift operator. left operands value moved left number of bits specified right operand. << 2 give 240 1111 0000 binary right shift operator >>. left operands value moved right number of bits specified right operand. >> 2 give 15 1111
java
Comments
Post a Comment