1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| import java.util.Arrays;
public class vnctfcm1apk{ public static byte[] bencrypt(byte[] input, byte[] keys) { return input.length == 0 ? input : toByteArray(encrypt(toIntArray(input, false), toIntArray(keys, false)), false); }
public static int[] encrypt(int[] input, int[] keys) { System.out.println("input: " + Arrays.toString(input)); System.out.println("keys : " + Arrays.toString(keys));
int rounds = 52 / input.length + 6; int rnd_s = 0; int prev_int = input[input.length - 1]; do { rnd_s += -1640531527; int rnd_e = rnd_s >>> 2 & 3; System.out.println("[rnd_e:" + rnd_e + ", rnd_s:" + rnd_s + "]"); int ind; for(ind = 0; ind < input.length - 1; ++ind) { int ind_chr = input[ind] + ((prev_int >>> 5 ^ input[ind + 1] << 2) + (input[ind + 1] >>> 3 ^ prev_int << 4) ^ (rnd_s ^ input[ind + 1]) + (keys[ind & 3 ^ rnd_e] ^ prev_int)); input[ind] = ind_chr; prev_int = ind_chr; }
int next_int = input[0]; int last_ind = input.length - 1; int lc = input[last_ind] + ((prev_int >>> 5 ^ next_int << 2) + (next_int >>> 3 ^ prev_int << 4) ^ (rnd_s ^ next_int) + (keys[ind & 3 ^ rnd_e] ^ prev_int)); input[last_ind] = lc; prev_int = lc; --rounds; } while(rounds > 0); System.out.print("try encrypt: ["); for(byte a:toByteArray(input, false)){ System.out.print(a + ","); } System.out.println("]");
return input; }
public static int[] decrypt(int[] aim, int[] keys){ int[] preaim = new int[aim.length]; int[] rnd_s = new int[]{-1640531527,1013904242,-626627285,2027808484,387276957,-1253254570,1401181199,-239350328,-1879881855,774553914}; int[] rnd_e = new int[]{2,0,2,1,3,1,3,2,0,2};
for(int rnd=9;rnd>=0;rnd--){
int ind = aim.length - 1; int last_ind = aim.length - 1; int prev_int = aim[last_ind-1]; int next_int = aim[0]; int lc = aim[last_ind];
preaim[last_ind] = (lc - ((prev_int >>> 5 ^ next_int << 2) + (next_int >>> 3 ^ prev_int << 4) ^ (rnd_s[rnd] ^ next_int) + (keys[ind & 3 ^ rnd_e[rnd]] ^ prev_int)) );
for(ind = aim.length - 1 -1; ind>=0; ind--){ if(ind==0) prev_int = preaim[aim.length-1]; else prev_int = aim[ind-1]; next_int = preaim[ind+1]; preaim[ind] = (aim[ind] - ((prev_int >>> 5 ^ next_int << 2) + (next_int >>> 3 ^ prev_int << 4) ^ (rnd_s[rnd] ^ next_int) + (keys[ind & 3 ^ rnd_e[rnd]] ^ prev_int)) ); }
aim = preaim; } System.out.print("try decrypt: ["); for(byte a:toByteArray(aim, false)){ System.out.print(a + ","); } System.out.println("]"); System.out.print("try flag: "); for(byte a:toByteArray(aim, false)){ System.out.print((char)a); } System.out.println(""); return aim; }
public static void main(String[] argc){
int rounds = 7; byte[] aim_byte=new byte[]{68, 39, -92, 108, -82, -18, 72, -55, 74, -56, 38, 11, 60, 84, 97, -40, 87, 71, 99, -82, 120, 104, 0x2F, -71, -58, -57, 0, 33, 42, 38, -44, -39, -60, 0x71, -2, 92, -75, 0x76, -77, 50, (byte)0x87, 43, 0x20, -106}; int[] aim_int =new int[]{0b1101100101001000010011101000100,0b11001001010010001110111010101110,0b1011001001101100100001001010,0b11011000011000010101010000111100,0b10101110011000110100011101010111,0b10111001001011110110100001111000,0b100001000000001100011111000110,0b11011001110101000010011000101010,0b1011100111111100111000111000100,0b110010101100110111011010110101,0b10010110001000000010101110000111}; byte[] try_byte=new byte[]{86,78,67,84,70,123,57,51,101,101,55,54,56,56,45,102,50,49,54,45,52,50,99,98,45,97,53,99,50,45,49,57,49,102,102,52,101,52,49,50,98,97,125,0}; decrypt( toIntArray(aim_byte, false), toIntArray("H4pPY_VNCTF!!OvO".getBytes(), false) );
int[] ens = new int[11]; ens = encrypt( toIntArray(try_byte, false) , toIntArray("H4pPY_VNCTF!!OvO".getBytes(), false) ); System.out.println("encoded msg length = " + toByteArray(ens, false).length); }
private static int[] toIntArray(byte[] arg7, boolean arg8) { int[] result; int v0 = (arg7.length & 3) == 0 ? arg7.length >>> 2 : (arg7.length >>> 2) + 1; if(arg8) { result = new int[v0 + 1]; result[v0] = arg7.length; } else { result = new int[v0]; }
int i; for(i = 0; i < arg7.length; ++i) { int v3 = i >>> 2; result[v3] |= (arg7[i] & 0xFF) << ((i & 3) << 3); }
return result; }
private static byte[] toByteArray(int[] arg5, boolean arg6) { int n = arg5.length << 2; if(arg6) { int m = arg5[arg5.length - 1]; if(m > n) { return null; }
n = m; }
byte[] result = new byte[n]; int i; for(i = 0; i < n; ++i) { result[i] = (byte)(arg5[i >>> 2] >>> ((i & 3) << 3) & 0xFF); }
return result; } }
|