Javakurs/Übungsaufgaben/Crack the Password/Musterloesung: Unterschied zwischen den Versionen
< Javakurs | Übungsaufgaben | Crack the Password
Mario (Diskussion | Beiträge) K (On The fly lösung ...) |
K |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 7: | Zeile 7: | ||
<pre> | <pre> | ||
| − | public class | + | 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> | ||
Aktuelle Version vom 4. März 2013, 19:37 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!");
}
}
}
}