Exemple #1
0
 public static void main(String args[]) throws Exception {
   Scanner cin = new Scanner(System.in);
   BigInteger s, M;
   int p, i;
   while (cin.hasNext()) {
     p = cin.nextInt();
     s = BigInteger.valueOf(4);
     M = BigInteger.ONE;
     M = M.shiftLeft(p).subtract(BigInteger.ONE);
     for (i = 0; i < p - 2; ++i) {
       s = s.multiply(s).subtract(BigInteger.valueOf(2));
       while (s.bitLength() > p) {
         s = s.shiftRight(p).add(s.and(M));
       }
     }
     if (s.compareTo(BigInteger.ZERO) == 0 || s.compareTo(M) == 0) {
       System.out.println(0);
       continue;
     }
     String ans = "";
     while (s.compareTo(BigInteger.ZERO) > 0) {
       long buf = s.mod(BigInteger.valueOf(16)).longValue();
       ans += Integer.toHexString((int) buf);
       s = s.divide(BigInteger.valueOf(16));
     }
     for (i = ans.length() - 1; i >= 0; --i) System.out.print(ans.charAt(i));
     System.out.println();
   }
 }
  private void decryptTabelEntry(BigInteger[] cLabels) {
    int col = 0;

    for (int i = 0; i < nCIBits; i++) if (cLabels[i].testBit(0)) col |= (1 << i);

    BigInteger target = EGTable[col];

    BigInteger colKey = BigInteger.ZERO;
    for (int k = nCIBits - 1; k >= 0; k--)
      colKey = colKey.shiftLeft(Wire.labelBitLength).xor(cLabels[k]);

    BigInteger res = Cipher.decrypt(colKey, target, nBits * Wire.labelBitLength);

    BigInteger mask = BigInteger.ONE.shiftLeft(Wire.labelBitLength).subtract(BigInteger.ONE);
    for (int k = nBits - 1; k >= 0; k--)
      outputLabels[k] = res.shiftRight(Wire.labelBitLength * k).and(mask);
  }