Skip to content

Instantly share code, notes, and snippets.

@LordNoteworthy
Created June 21, 2014 22:05
Show Gist options
  • Save LordNoteworthy/408b2d09321622f1e96d to your computer and use it in GitHub Desktop.
Save LordNoteworthy/408b2d09321622f1e96d to your computer and use it in GitHub Desktop.
Hackknowledge 2013 Final bin500 CrackMe
import java.util.Scanner;
public class Prism
{
public static final int ROTATE_LEFT = 1;
public static final int ROTATE_RIGHT = 2;
public static int calcmask(int bitstorotate, int direction)
{
int mask = 0;
int c;
if (bitstorotate == 0)
return 0;
c = 0x80000000;
mask = (c >> bitstorotate);
if (direction == ROTATE_RIGHT)
{
mask = (c >> (32 - bitstorotate));
mask = ~mask;
}
else
mask = (c >> bitstorotate);
return mask;
}
public static int rotl(int value, int bitstorotate, int sizet)
{
int tmprslt =0;
int mask=0;;
int target=0;
bitstorotate %= sizet;
// determine which bits will be impacted by the rotate
mask = calcmask(bitstorotate, ROTATE_LEFT);
// shift the mask into the correct place (i.e. if we are delaying with a byte rotate, we
// need to ensure we have the mask setup for a byte or 8 bits)
mask >>>= (32 - sizet);
// save off the affected bits
tmprslt = value & mask;
// perform the actual rotate
target = (value << bitstorotate);
// now shift the saved off bits
tmprslt >>>= (sizet - bitstorotate);
// add the rotated bits back in (in the proper location)
target |= tmprslt;
// now return the result
return target;
}
public static byte rotl(byte value, int bitstorotate)
{
byte result;
result = (byte) rotl((0x000000ff & value), bitstorotate, 8);
return result;
}
public static String convertHexToString(String hex){
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
//49204c6f7665204a617661 split into two characters 49, 20, 4c...
for( int i=0; i<hex.length()-1; i+=2 ){
//grab the hex in pairs
String output = hex.substring(i, (i + 2));
//convert hex to decimal
int decimal = Integer.parseInt(output, 16);
//convert the decimal to character
sb.append((char)decimal);
temp.append(decimal);
}
return sb.toString();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Name ? : ");
String str = sc.nextLine();
String serial = "";
boolean found = false;
for ( int c= 0; c< str.length(); c++)
{
found = false;
for ( int i = 0x20; i <= 0x7E; i++)
{
for (int j= 0x20; j <= 0x7E; j++)
{
int x = (i - 0x41) << 4;
int y = j - 0x41;
int z = (x + y) ^ 0x43; //0x48
int f = rotl((byte) z, 3);
f = rotl((byte) z, 3);
f = rotl((byte) z, 3);
if(f == str.charAt(c) && !found)
{
found = true;
serial = serial + convertHexToString((Integer.toHexString(i))) + convertHexToString((Integer.toHexString(j)));
}
}
}
}
System.out.println(serial);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment