Created
October 13, 2014 08:55
-
-
Save volpino/caf13d33ca52ffcf3f4c to your computer and use it in GitHub Desktop.
Numdroid - ASIS CTF Finals 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.asis.ctf2014.numdriod.tools; | |
import java.util.*; | |
public class ArrayTools | |
{ | |
public static Integer[] Range(final int n, final int n2) { | |
final Integer[] array = new Integer[n2 - n]; | |
for (int i = 0; i < array.length; ++i) { | |
array[i] = n + i; | |
} | |
return array; | |
} | |
public static <T> void each(final List<T> list, final EachAction<T> eachAction) { | |
final Iterator<T> iterator = list.iterator(); | |
while (iterator.hasNext()) { | |
eachAction.action((T)((Object)iterator.next())); | |
} | |
} | |
public static <T> void each(final T[] array, final EachAction<T> eachAction) { | |
for (int length = array.length, i = 0; i < length; ++i) { | |
eachAction.action(array[i]); | |
} | |
} | |
public static <T> void each_with_index(final T[] array, final EachIndexAction<T> eachIndexAction) { | |
for (int i = 0; i < array.length; ++i) { | |
eachIndexAction.action(i, array[i]); | |
} | |
} | |
public static <T, S> List<S> map(final List<T> list, final MapAction<T, S> mapAction) { | |
final ArrayList<?> list2 = new ArrayList<?>(); | |
final Iterator<T> iterator = list.iterator(); | |
while (iterator.hasNext()) { | |
list2.add((Object)mapAction.action((T)((Object)iterator.next()))); | |
} | |
return list2; | |
} | |
public static <T, S> List<S> map(final T[] array, final MapAction<T, S> mapAction) { | |
final ArrayList<?> list = new ArrayList<?>(); | |
for (int length = array.length, i = 0; i < length; ++i) { | |
list.add((Object)mapAction.action(array[i])); | |
} | |
return list; | |
} | |
public static <T> List<T> select(final List<T> list, final SelectAction<T> selectAction) { | |
final ArrayList<?> list2 = new ArrayList<?>(); | |
for (final T t : list) { | |
if (selectAction.action(t)) { | |
list2.add((Object)t); | |
} | |
} | |
return list2; | |
} | |
public static <T> List<T> select(final T[] array, final SelectAction<T> selectAction) { | |
final ArrayList<?> list = new ArrayList<?>(); | |
for (final T t : array) { | |
if (selectAction.action(t)) { | |
list.add((Object)t); | |
} | |
} | |
return list; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.asis.ctf2014.numdriod; | |
import java.security.*; | |
import java.util.*; | |
import android.content.*; | |
import io.asis.ctf2014.numdriod.tools.*; | |
public class Verify | |
{ | |
private static String OneWayFunction(final String s) { | |
final MessageDigest instance; | |
final byte[] digest; | |
final List<Object> map = ArrayTools.map(ArrayTools.select((List<Object>)ArrayTools.map(new String[] { "MD2", "MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512" }, (MapAction<String, S>)new MapAction<String, byte[]>() { | |
public byte[] action(final String algorithm) { | |
final byte[] digest; | |
try { | |
final MessageDigest instance = MessageDigest.getInstance(algorithm); | |
instance.update(s.getBytes()); | |
digest = instance.digest(); | |
} | |
catch (NoSuchAlgorithmException ex) { | |
return null; | |
} | |
return digest; | |
} | |
}), (SelectAction<Object>)new SelectAction<byte[]>() { | |
public boolean action(final byte[] array) { | |
return array != null; | |
} | |
}), (MapAction<Object, Object>)new MapAction<byte[], byte[]>() { | |
public byte[] action(final byte[] array) { | |
final byte[] array2 = new byte[8]; | |
for (int i = 0; i < array2.length / 2; ++i) { | |
array2[i] = array[i]; | |
} | |
for (int j = 0; j < array2.length / 2; ++j) { | |
array2[j + array2.length / 2] = array[-2 + (array.length - j)]; | |
} | |
return array2; | |
} | |
}); | |
final byte[] input = new byte[8 * map.size()]; | |
for (int i = 0; i < input.length; ++i) { | |
input[i] = ((byte[])((Object)map.get(i % map.size())))[i / map.size()]; | |
} | |
final StringBuilder sb; | |
final int length; | |
try { | |
instance = MessageDigest.getInstance("MD5"); | |
instance.update(input); | |
digest = instance.digest(); | |
sb = new StringBuilder(); | |
length = digest.length; | |
} | |
catch (NoSuchAlgorithmException) { | |
return ""; | |
} | |
int j = 0; | |
while (j < length) { | |
while (true) { | |
Object hexString = null; | |
try { | |
hexString = Integer.toHexString(255 & digest[j]); | |
} | |
catch (NoSuchAlgorithmException) {} | |
Label_0190: { | |
final String string; | |
Label_0213: { | |
try { | |
if (((String)hexString).length() < 2) { | |
break Label_0213; | |
} | |
sb.append((String)hexString); | |
} | |
catch (NoSuchAlgorithmException) {} | |
++j; | |
break; | |
try { | |
string = "0" + (String)hexString; | |
} | |
catch (NoSuchAlgorithmException) {} | |
} | |
hexString = string; | |
break Label_0190; | |
} | |
} | |
} | |
final String string2; | |
try { | |
string2 = sb.toString(); | |
} | |
catch (NoSuchAlgorithmException) {} | |
return string2; | |
} | |
public static boolean isOk(final Context context, final String s) { | |
String substring = s; | |
if (s.length() > 7) { | |
substring = s.substring(0, 7); | |
} | |
final String oneWayFunction = OneWayFunction(substring); | |
DebugTools.log("digest: " + substring + " => " + oneWayFunction); | |
final boolean equals = oneWayFunction.equals("be790d865f2cea9645b3f79c0342df7e"); | |
boolean b = false; | |
if (equals) { | |
b = true; | |
} | |
return b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment