File size: 3,339 Bytes
847eab0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import streamlit as st
import random
from faker import Faker
from datetime import datetime, timedelta

fake = Faker()

# ---------------- UI CONFIG ----------------
st.set_page_config(
    page_title="Credit Card Generator",
    layout="centered",
    initial_sidebar_state="collapsed"
)

# ---- Dark Mode Styling ----
st.markdown("""
<style>
body {
    background-color: #0e1117;
    color: #ffffff;
}
.stButton>button {
    background-color: #4CAF50;
    color: white;
    border-radius: 8px;
    height: 3em;
    width: 100%;
}
.card-box {
    background: linear-gradient(135deg, #1f2937, #111827);
    padding: 20px;
    border-radius: 12px;
    color: white;
    font-family: monospace;
}
.copy-btn {
    margin-top: 10px;
}
</style>
""", unsafe_allow_html=True)

st.title("💳 Credit Card Generator")

st.caption("Generate **test credit card details** for development and QA use only.")

# ---------------- INPUT ----------------
card_type = st.selectbox("Select Card Type", ["VISA", "MASTERCARD"])
generate = st.button("Generate Card")

# ---------------- CORE LOGIC ----------------

def luhn_generate(prefix, length):
    number = prefix
    while len(number) < length - 1:
        number += str(random.randint(0, 9))

    digits = [int(d) for d in number]

    for i in range(len(digits) - 1, -1, -2):
        digits[i] *= 2
        if digits[i] > 9:
            digits[i] -= 9

    checksum = (10 - (sum(digits) % 10)) % 10
    return number + str(checksum)

def format_card(number):
    return " ".join([number[i:i+4] for i in range(0, len(number), 4)])

def generate_expiry():
    future_date = datetime.now() + timedelta(days=random.randint(365, 1825))
    return future_date.strftime("%m/%y")

def generate_cvv():
    return str(random.randint(100, 999))

def detect_country(bin_prefix):
    bin_map = {
        "4": "USA / International (VISA)",
        "51": "USA (MasterCard)",
        "52": "Canada",
        "53": "UK",
        "54": "Germany",
        "55": "France"
    }
    return bin_map.get(bin_prefix[:2], "Unknown")

def generate_card(card_type):
    if card_type == "VISA":
        prefix = "4"
        length = 16
    else:
        prefix = str(random.choice(range(51, 56)))
        length = 16

    number = luhn_generate(prefix, length)

    return {
        "number": number,
        "formatted": format_card(number),
        "name": fake.name(),
        "zip": fake.zipcode(),
        "expiry": generate_expiry(),
        "cvv": generate_cvv(),
        "country": detect_country(prefix)
    }

# ---------------- OUTPUT ----------------

if generate:
    card = generate_card(card_type)

    st.success("Card Generated")

    st.markdown(f"""
    <div class="card-box">
        <h3>{card_type}</h3>
        <p style="font-size:20px;">{card['formatted']}</p>
        <p>{card['name']}</p>
        <p>EXP: {card['expiry']} | CVV: {card['cvv']}</p>
    </div>
    """, unsafe_allow_html=True)

    st.write(f"**ZIP Code:** {card['zip']}")
    st.write(f"**Country (BIN):** {card['country']}")

    # -------- Copy Buttons --------
    st.subheader("Copy Details")

    st.code(card["number"], language="text")
    st.code(card["formatted"], language="text")
    st.code(card["cvv"], language="text")

    st.info("⚠️ These are fake/generated details for testing only. Not usable for real transactions.")