Sitzung: Jeden Freitag in der Vorlesungszeit ab 16 Uhr c. t. im MAR 0.005. In der vorlesungsfreien Zeit unregelmäßig (Jemensch da?). Macht mit!

Javakurs/Übungsaufgaben/Crack the Password/Musterloesung: Unterschied zwischen den Versionen

K (On The fly lösung ...)
 
K
Zeile 7: Zeile 7:
  
 
<pre>
 
<pre>
public class CrackPWD{
+
public class CrackPW {
 
+
public static boolean checkPasscode(int H4X0R) {
public static boolean checkPasscode(int H4X0R){
 
 
// returns true if passcode is valid
 
// returns true if passcode is valid
 
boolean result = false;
 
boolean result = false;
for(int E1337=42; E1337<=(52^(0x6c)); E1337+=(3<<(14%6))){
+
for (int E1337 = 42; E1337 <= (52 ^ (0x6c)); E1337 += (3 << (14 % 6))) {
if(result=((++E1337|E1337+(2>>>1))^(1+H4X0R))==(123456789&0))
+
if (result = ((++E1337 | E1337 + (2 >>> 1)) ^ (1 + H4X0R)) == (123456789 & 0))
 
break;
 
break;
 
}
 
}
Zeile 20: Zeile 19:
  
 
public static void main(String[] arguments) {
 
public static void main(String[] arguments) {
for(int i = -99999; i < 99999; i++)
+
for (int i = -99999; i < 99999; i++)
if(checkPasscode(i)) {
+
if (checkPasscode(i)) {
System.out.println(i+" is the key!");
+
System.out.println(i + " is the key!");
 
}
 
}
 
}
 
}
 
}
 
}
 
 
</pre>
 
</pre>

Version vom 4. März 2013, 13:36 Uhr

46 is the key!
56 is the key!
70 is the key!
82 is the key!

Code:

public class CrackPW {
	public static boolean checkPasscode(int H4X0R) {
		// returns true if passcode is valid
		boolean result = false;
		for (int E1337 = 42; E1337 <= (52 ^ (0x6c)); E1337 += (3 << (14 % 6))) {
			if (result = ((++E1337 | E1337 + (2 >>> 1)) ^ (1 + H4X0R)) == (123456789 & 0))
				break;
		}
		return result;
	}

	public static void main(String[] arguments) {
		for (int i = -99999; i < 99999; i++)
			if (checkPasscode(i)) {
				System.out.println(i + " is the key!");
			}
	}
}