Added Fake CreditCard generator

This commit is contained in:
Finn
2025-11-10 19:38:04 +01:00
parent 54c1f7ea08
commit 20be55ff5b
3 changed files with 125 additions and 17 deletions

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2025 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package dev.unlegitdqrk.unlegitlibrary.bank;
public class CardBrand {
public static final CardBrand VISA = new CardBrand(16, new String[]{"4"});
public static final CardBrand AMERICANEXPRESS = new CardBrand(15, new String[]{"34","37"});
public static final CardBrand MASTERCARD = new CardBrand(16, new String[] {
"51","52","53","54","55",
"2221","2222","2223","2720"
});
private final int length;
private final String[] prefixes;
public CardBrand(int length, String[] prefixes) {
this.length = length;
this.prefixes = prefixes;
}
public int getLength() {
return length;
}
public String[] getPrefixes() {
return prefixes;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) 2025 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package dev.unlegitdqrk.unlegitlibrary.bank;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class CreditCard {
private final String cardNumber;
private final CardBrand cardBrand;
private final Random random;
public CardBrand getCardBrand() {
return cardBrand;
}
public Random getRandom() {
return random;
}
public String getCardNumber() {
return cardNumber;
}
public CreditCard(CardBrand cardBrand) {
this.cardBrand = cardBrand;
this.random = new Random();
this.cardNumber = generateCardNumber();
}
public CreditCard(CardBrand cardBrand, int seed) {
this.cardBrand = cardBrand;
this.random = new Random(seed);
this.cardNumber = generateCardNumber();
}
private String generateCardNumber() {
int totalLength = cardBrand.getLength();
List<Integer> digits = new ArrayList<>(totalLength);
String chosenPrefix = null;
if (cardBrand.getPrefixes() != null && cardBrand.getPrefixes().length > 0) {
String[] prefixes = cardBrand.getPrefixes();
chosenPrefix = prefixes[random.nextInt(prefixes.length)];
for (char c : chosenPrefix.toCharArray()) {
digits.add(c - '0');
}
} else digits.add(1 + random.nextInt(9));
while (digits.size() < totalLength - 1) digits.add(random.nextInt(10));
int checkDigit = computeLuhnCheckDigit(digits, totalLength);
digits.add(checkDigit);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < digits.size(); i++) {
sb.append(digits.get(i));
if ((i + 1) % 4 == 0 && i != digits.size() - 1) sb.append(' ');
}
return sb.toString();
}
private int computeLuhnCheckDigit(List<Integer> digitsWithoutCheck, int totalLength) {
int sum = 0;
int n = digitsWithoutCheck.size() + 1;
for (int i = 0; i < digitsWithoutCheck.size(); i++) {
int digit = digitsWithoutCheck.get(i);
int posFromRight = n - i;
boolean shouldDouble = (posFromRight % 2 == 0);
if (shouldDouble) {
int d = digit * 2;
if (d > 9) d -= 9;
sum += d;
} else sum += digit;
}
int mod = sum % 10;
return (10 - mod) % 10;
}
}

View File

@@ -1,17 +0,0 @@
/*
* Copyright (C) 2025 UnlegitDqrk - All Rights Reserved
*
* You are unauthorized to remove this copyright.
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
* See LICENSE-File if exists
*/
package dev.unlegitdqrk.unlegitlibrary.window;
public class Window {
WinUser.WNDCLASSEX wndClass = new WinUser.WNDCLASSEX();
public Window(String tile, int x, int y, int width, int height) {
WinUs
}
}