Javakurs/Übungsaufgaben/Crack the Password/Musterloesung: Unterschied zwischen den Versionen
< Javakurs | Übungsaufgaben | Crack the Password
K |
K |
||
Zeile 19: | 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!"); } } } }