-
[v9.0ake] Passwort-Kodierung
Laut SeBi gehen auch Credits zu Flav.
Weil SeBi zu faul war es zu veröffentlichen, hab ich ihn gefragt ob ich es machen soll und joa :
Spoiler:
Code:
/**
*
* @author SeBi
*/
public class Password {
private static String encrypt1(String str, String key) {
int strLength = str.length();
int keyLength = key.length();
int k = keyLength ^ strLength << 3;
int bufferLength = keyLength > strLength ? keyLength : strLength;
StringBuilder buffer = new StringBuilder(bufferLength);
int strChar = str.charAt(0);
int keyChar = key.charAt(0);
for (int i = 0; i < bufferLength; i++) {
if (strChar >= keyLength) {
strChar = 0;
}
if (keyChar >= strLength) {
keyChar = 0;
}
buffer.append((char) (str.charAt(keyChar) ^ key.charAt(strChar) ^ k));
strChar++;
keyChar++;
}
return buffer.toString();
}
private static String encrypt2(String str, String key) {
int strLength = str.length();
int keyLength = key.length();
int k = strLength ^ keyLength << 4;
int bufferLength = keyLength > strLength ? keyLength : strLength;
StringBuilder buffer = new StringBuilder(bufferLength);
for (int i = 0; i < bufferLength; i++) {
buffer.append((char) (str.charAt(i % strLength) ^ key.charAt(i % keyLength) ^ k));
}
return buffer.toString();
}
private static int hash(String str) {
int i = 0;
int j = 0;
int strLength = str.length();
if (strLength < 19) {
for (int n = strLength - 1; n >= 0; n--) {
i = i * 3 + str.charAt(n);
j = j * 5 + str.charAt(strLength - n - 1);
}
} else {
int m = strLength / 19;
int n = strLength - 1;
while (n >= 0) {
i = i * 5 + str.charAt(n);
j = j * 3 + str.charAt(strLength - n - 1);
n -= m;
}
}
int k = i ^ j;
return k & 0xFFFFFF ^ k >> 24;
}
private static int toInt(String str) {
int i1 = 0;
int i2 = 0;
int i3 = 0;
int i4 = 0;
int i5 = str.length();
while (i4 < i5) {
i2 = i2 * ((i3 & 0x3) != 3 ? 5 : 3) + str.charAt(i5 - i4 - 1);
i3 = i1 ^ i2;
i1 = i1 * ((i3 & 0x4) == 0 ? 3 : 7) + str.charAt(i4 * 43973 % i5);
i4++;
}
return i3 >>> 26 ^ (i2 ^ i1) & 0x3FFFFFF;
}
public static int hashPassword(String password, String key) {
key = encrypt1(key, "PVobnFeSCkn");
int i = key.length() / 2;
i = (i * i + i + 10) % key.length();
i = (i * i + i + 12) % key.length();
i = i * 37 % key.length();
if (i == 0) {
i = key.length() / 2;
}
key = encrypt1(key.substring(i), "aW") + key.substring(0, i);
i = toInt(key) % key.length();
i = (i * i + i + 19) % key.length();
key = encrypt1(new StringBuilder().append(toInt(key.substring(0, i)) * toInt(key.substring(0, i))).toString(), key.substring(i)) + encrypt1(new StringBuilder().append(toInt(key.substring(i)) * toInt(key.substring(i))).append(885800044).toString(), key.substring(0, i));
return hash(encrypt2(password, key));
}
}
-
Ähnliche Themen
-
Von MiBo im Forum Knuddels Programmierung
Antworten: 0
Letzter Beitrag: 05.02.2013, 15:47
-
Antworten: 2
Letzter Beitrag: 25.01.2013, 17:56
-
Von Brainy im Forum Sourcecode
Antworten: 8
Letzter Beitrag: 29.07.2012, 17:30
-
Von Flav im Forum Sourcecode
Antworten: 0
Letzter Beitrag: 09.04.2012, 00:57
-
Von Flav im Forum Sourcecode
Antworten: 8
Letzter Beitrag: 29.05.2011, 23:30