/** * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually * should go to struct. * * @param from * @param to * @param excludes * @return * @throws Exception */ public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception { Arrays.sort(excludes); for (Field f : from.fields()) { if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue; Object o = f.get(from); if (o == null) continue; Field tof = to.getField(f.getName()); if (tof != null) try { tof.set(to, Converter.cnv(tof.getGenericType(), o)); } catch (Exception e) { System.out.println( "Failed to convert " + f.getName() + " from " + from.getClass() + " to " + to.getClass() + " value " + o + " exception " + e); } } return to; }
public int crack(String[] plaintexts, String[] ciphertexts) { long[] in = parse(plaintexts); long[] out = parse(ciphertexts); int ans = 0; for (long cur : in) { long key = cur ^ out[0]; boolean ok = true; for (long na : out) { if (Arrays.binarySearch(in, (key ^ na)) < 0) ok = false; } if (ok) ans++; } return ans; }