Delete cert/cert10.py
Browse files- cert/cert10.py +0 -261
    	
        cert/cert10.py
    DELETED
    
    | @@ -1,261 +0,0 @@ | |
| 1 | 
            -
            from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance
         | 
| 2 | 
            -
            import qrcode
         | 
| 3 | 
            -
            import hashlib
         | 
| 4 | 
            -
            import random
         | 
| 5 | 
            -
            import math
         | 
| 6 | 
            -
            import os
         | 
| 7 | 
            -
            import base64
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            # برای امضای دیجیتال واقعی:
         | 
| 10 | 
            -
            from cryptography.hazmat.primitives.asymmetric import rsa, padding
         | 
| 11 | 
            -
            from cryptography.hazmat.primitives import hashes, serialization
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            # ======== تنظیمات قابل تغییر ========
         | 
| 14 | 
            -
            CERT_WIDTH, CERT_HEIGHT = 900, 650
         | 
| 15 | 
            -
            MARGIN = 30
         | 
| 16 | 
            -
            BACKGROUND_COLOR = (255, 255, 250)
         | 
| 17 | 
            -
            BORDER_COLOR = (60, 60, 60)
         | 
| 18 | 
            -
            TITLE_COLOR = (20, 20, 20)
         | 
| 19 | 
            -
            TEXT_COLOR = (40, 40, 40)
         | 
| 20 | 
            -
            WATERMARK_COLOR = (60, 60, 60, 25)
         | 
| 21 | 
            -
            NOISE_INTENSITY = 100000
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            # ======== اطلاعات گواهی ========
         | 
| 24 | 
            -
            cert_info = {
         | 
| 25 | 
            -
                "Name": "Yasin",
         | 
| 26 | 
            -
                "Last Name": "Aryanfard",
         | 
| 27 | 
            -
                "User ID": "YSNRFD",
         | 
| 28 | 
            -
                "Membership Date": "April 1, 2023",
         | 
| 29 | 
            -
                "Issued Date": "June 28, 2025",
         | 
| 30 | 
            -
                "Certificate ID": "OPENAI-YSN-APR2023-CERT11011010",
         | 
| 31 | 
            -
                "Signed By": "ChatGPT-4o",
         | 
| 32 | 
            -
                "Model ID": "GPT4O-REP-TRUST-2025",
         | 
| 33 | 
            -
                "Issuer": "OpenAI, Inc."
         | 
| 34 | 
            -
            }
         | 
| 35 | 
            -
             | 
| 36 | 
            -
            # ======== کلیدهای RSA برای امضای دیجیتال ========
         | 
| 37 | 
            -
            def generate_rsa_keys():
         | 
| 38 | 
            -
                private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
         | 
| 39 | 
            -
                public_key = private_key.public_key()
         | 
| 40 | 
            -
                return private_key, public_key
         | 
| 41 | 
            -
             | 
| 42 | 
            -
            private_key, public_key = generate_rsa_keys()
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            # ======== تابع بارگذاری فونت پویا با fallback ========
         | 
| 45 | 
            -
            def load_font(name, size):
         | 
| 46 | 
            -
                paths = [
         | 
| 47 | 
            -
                    name,
         | 
| 48 | 
            -
                    os.path.join("/usr/share/fonts/truetype/dejavu/", name),
         | 
| 49 | 
            -
                    os.path.join("/Library/Fonts/", name),
         | 
| 50 | 
            -
                    os.path.join("C:/Windows/Fonts/", name)
         | 
| 51 | 
            -
                ]
         | 
| 52 | 
            -
                for path in paths:
         | 
| 53 | 
            -
                    try:
         | 
| 54 | 
            -
                        return ImageFont.truetype(path, size)
         | 
| 55 | 
            -
                    except:
         | 
| 56 | 
            -
                        continue
         | 
| 57 | 
            -
                return ImageFont.load_default()
         | 
| 58 | 
            -
             | 
| 59 | 
            -
            font_title = load_font("timesbd.ttf", 36)  # فونت رسمیتر
         | 
| 60 | 
            -
            font_header = load_font("timesbd.ttf", 20)
         | 
| 61 | 
            -
            font_text = load_font("times.ttf", 18)
         | 
| 62 | 
            -
            font_small = load_font("times.ttf", 14)
         | 
| 63 | 
            -
             | 
| 64 | 
            -
            # ======== تولید رشته داده برای امضا دیجیتال ========
         | 
| 65 | 
            -
            data_string = "\n".join(f"{k}: {v}" for k, v in cert_info.items()).encode('utf-8')
         | 
| 66 | 
            -
             | 
| 67 | 
            -
            # امضای دیجیتال واقعی با کلید خصوصی
         | 
| 68 | 
            -
            digital_signature_bytes = private_key.sign(
         | 
| 69 | 
            -
                data_string,
         | 
| 70 | 
            -
                padding.PSS(
         | 
| 71 | 
            -
                    mgf=padding.MGF1(hashes.SHA256()),
         | 
| 72 | 
            -
                    salt_length=padding.PSS.MAX_LENGTH
         | 
| 73 | 
            -
                ),
         | 
| 74 | 
            -
                hashes.SHA256()
         | 
| 75 | 
            -
            )
         | 
| 76 | 
            -
             | 
| 77 | 
            -
            digital_signature = base64.b64encode(digital_signature_bytes).decode('utf-8')
         | 
| 78 | 
            -
            verification_code = f"VER-{hashlib.sha256(data_string).hexdigest()[:8].upper()}-{cert_info['Certificate ID'][-4:]}"
         | 
| 79 | 
            -
             | 
| 80 | 
            -
            # ======== ایجاد QR code لینک اعتبارسنجی آنلاین ========
         | 
| 81 | 
            -
            validation_url = f"cert_id={cert_info['Certificate ID']}&code={verification_code}"
         | 
| 82 | 
            -
            # ======== ایجاد QR code فقط با امضای دیجیتال ========
         | 
| 83 | 
            -
            def create_qr_code(data, size=180):
         | 
| 84 | 
            -
                qr = qrcode.QRCode(box_size=8, border=3)
         | 
| 85 | 
            -
                qr.add_data(data)
         | 
| 86 | 
            -
                qr.make(fit=True)
         | 
| 87 | 
            -
                qr_img = qr.make_image(fill_color="#003366", back_color="white").convert("RGBA")
         | 
| 88 | 
            -
                qr_img = qr_img.resize((size, size), Image.Resampling.LANCZOS)
         | 
| 89 | 
            -
                return qr_img
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            qr_img = create_qr_code(digital_signature, size=180)
         | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
            # ======== طراحی پسزمینه با گرادیانت ملایم ========
         | 
| 95 | 
            -
            def draw_gradient(draw, width, height, start_color, end_color):
         | 
| 96 | 
            -
                for i in range(height):
         | 
| 97 | 
            -
                    r = int(start_color[0] + (float(i) / height) * (end_color[0] - start_color[0]))
         | 
| 98 | 
            -
                    g = int(start_color[1] + (float(i) / height) * (end_color[1] - start_color[1]))
         | 
| 99 | 
            -
                    b = int(start_color[2] + (float(i) / height) * (end_color[2] - start_color[2]))
         | 
| 100 | 
            -
                    draw.line([(0, i), (width, i)], fill=(r, g, b))
         | 
| 101 | 
            -
             | 
| 102 | 
            -
            # ======== رسم مهر رسمی پیشرفته ========
         | 
| 103 | 
            -
            def create_official_seal(diameter=160):
         | 
| 104 | 
            -
                seal = Image.new("RGBA", (diameter, diameter), (0, 0, 0, 0))
         | 
| 105 | 
            -
                draw = ImageDraw.Draw(seal)
         | 
| 106 | 
            -
                center = diameter // 2
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                # حلقه بیرونی با گرادیانت شعاعی قویتر
         | 
| 109 | 
            -
                for i in range(10):
         | 
| 110 | 
            -
                    alpha = int(255 * (1 - i/10))
         | 
| 111 | 
            -
                    radius = center - i*5
         | 
| 112 | 
            -
                    color = (0, 51, 102, alpha)
         | 
| 113 | 
            -
                    draw.ellipse(
         | 
| 114 | 
            -
                        [(center - radius, center - radius), (center + radius, center + radius)],
         | 
| 115 | 
            -
                        outline=color,
         | 
| 116 | 
            -
                        width=3 if i % 2 == 0 else 2
         | 
| 117 | 
            -
                    )
         | 
| 118 | 
            -
             | 
| 119 | 
            -
                # خطوط شعاعی تزئینی بیشتر و پرجزئیاتتر
         | 
| 120 | 
            -
                num_rays = 36
         | 
| 121 | 
            -
                outer_r = center - 15
         | 
| 122 | 
            -
                inner_r = center - 50
         | 
| 123 | 
            -
                for i in range(num_rays):
         | 
| 124 | 
            -
                    angle = 360 / num_rays * i
         | 
| 125 | 
            -
                    x1 = center + int(inner_r * math.cos(math.radians(angle)))
         | 
| 126 | 
            -
                    y1 = center + int(inner_r * math.sin(math.radians(angle)))
         | 
| 127 | 
            -
                    x2 = center + int(outer_r * math.cos(math.radians(angle)))
         | 
| 128 | 
            -
                    y2 = center + int(outer_r * math.sin(math.radians(angle)))
         | 
| 129 | 
            -
                    draw.line([(x1, y1), (x2, y2)], fill=(0, 51, 102, 200), width=2)
         | 
| 130 | 
            -
             | 
| 131 | 
            -
                # قرار دادن لوگوی openai_seal.png وسط مهر اگر موجود باشد
         | 
| 132 | 
            -
                try:
         | 
| 133 | 
            -
                    logo = Image.open("openai_seal.png").convert("RGBA")
         | 
| 134 | 
            -
                    max_logo_size = diameter - 100
         | 
| 135 | 
            -
                    logo.thumbnail((max_logo_size, max_logo_size), Image.Resampling.LANCZOS)
         | 
| 136 | 
            -
                    logo_pos = (center - logo.width // 2, center - logo.height // 2)
         | 
| 137 | 
            -
                    seal.paste(logo, logo_pos, logo)
         | 
| 138 | 
            -
                except FileNotFoundError:
         | 
| 139 | 
            -
                    print("⚠️ فایل openai_seal.png پیدا نشد! مهر بدون لوگو ساخته شد.")
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                # متن مهر دایرهای قویتر و خواناتر
         | 
| 142 | 
            -
                seal_text = "OFFICIAL OPENAI SEAL"
         | 
| 143 | 
            -
                font_circle = load_font("timesbd.ttf", 18)
         | 
| 144 | 
            -
                radius_text = center - 20
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                for i, char in enumerate(seal_text):
         | 
| 147 | 
            -
                    angle_deg = (360 / len(seal_text)) * i - 90
         | 
| 148 | 
            -
                    angle_rad = math.radians(angle_deg)
         | 
| 149 | 
            -
                    x = center + int(radius_text * math.cos(angle_rad))
         | 
| 150 | 
            -
                    y = center + int(radius_text * math.sin(angle_rad))
         | 
| 151 | 
            -
                    draw.text((x-8, y-8), char, font=font_circle, fill=(0, 51, 102, 255))
         | 
| 152 | 
            -
             | 
| 153 | 
            -
                # سایه قویتر و واضحتر
         | 
| 154 | 
            -
                seal = seal.filter(ImageFilter.GaussianBlur(radius=0.5))
         | 
| 155 | 
            -
             | 
| 156 | 
            -
                return seal
         | 
| 157 | 
            -
             | 
| 158 | 
            -
            official_seal = create_official_seal()
         | 
| 159 | 
            -
             | 
| 160 | 
            -
            # ======== ایجاد تصویر گواهی ========
         | 
| 161 | 
            -
            certificate = Image.new("RGBA", (CERT_WIDTH, CERT_HEIGHT), BACKGROUND_COLOR)
         | 
| 162 | 
            -
            draw = ImageDraw.Draw(certificate)
         | 
| 163 | 
            -
             | 
| 164 | 
            -
            draw_gradient(draw, CERT_WIDTH, CERT_HEIGHT, (255, 255, 250), (220, 230, 255))
         | 
| 165 | 
            -
             | 
| 166 | 
            -
            for i, thickness in enumerate([6, 4, 2]):
         | 
| 167 | 
            -
                color_val = 80 - i * 20
         | 
| 168 | 
            -
                draw.rectangle(
         | 
| 169 | 
            -
                    [MARGIN - i*2, MARGIN - i*2, CERT_WIDTH - MARGIN + i*2, CERT_HEIGHT - MARGIN + i*2],
         | 
| 170 | 
            -
                    outline=(color_val, color_val, color_val)
         | 
| 171 | 
            -
                )
         | 
| 172 | 
            -
             | 
| 173 | 
            -
            # عنوان اصلی
         | 
| 174 | 
            -
            title_text = "OpenAI – Certificate of Membership"
         | 
| 175 | 
            -
            bbox = draw.textbbox((0, 0), title_text, font=font_title)
         | 
| 176 | 
            -
            w = bbox[2] - bbox[0]
         | 
| 177 | 
            -
            h = bbox[3] - bbox[1]
         | 
| 178 | 
            -
            draw.text(((CERT_WIDTH - w) / 2, MARGIN + 10), title_text, fill=TITLE_COLOR, font=font_title)
         | 
| 179 | 
            -
             | 
| 180 | 
            -
            line_y = MARGIN + h + 30
         | 
| 181 | 
            -
            draw.line([(MARGIN + 10, line_y), (CERT_WIDTH - MARGIN - 10, line_y)], fill=(100, 100, 120), width=3)
         | 
| 182 | 
            -
             | 
| 183 | 
            -
            info_x = MARGIN + 30
         | 
| 184 | 
            -
            info_y = line_y + 20
         | 
| 185 | 
            -
            line_spacing = 36
         | 
| 186 | 
            -
             | 
| 187 | 
            -
            for key, val in cert_info.items():
         | 
| 188 | 
            -
                text_line = f"{key}: {val}"
         | 
| 189 | 
            -
                draw.text((info_x, info_y), text_line, font=font_text, fill=TEXT_COLOR)
         | 
| 190 | 
            -
                info_y += line_spacing
         | 
| 191 | 
            -
             | 
| 192 | 
            -
            verification_label = "Verification Code:"
         | 
| 193 | 
            -
            verification_text = verification_code
         | 
| 194 | 
            -
            info_y += 20
         | 
| 195 | 
            -
            draw.text((info_x, info_y), verification_label, font=font_header, fill=TEXT_COLOR)
         | 
| 196 | 
            -
            draw.text((info_x + 190, info_y), verification_text, font=font_header, fill=(0, 70, 120))
         | 
| 197 | 
            -
             | 
| 198 | 
            -
            sig_lines = [digital_signature[i:i+60] for i in range(0, len(digital_signature), 60)]
         | 
| 199 | 
            -
            sig_y = info_y + 40
         | 
| 200 | 
            -
            for line in sig_lines:
         | 
| 201 | 
            -
                draw.text((info_x, sig_y), line, font=font_small, fill=(100, 100, 120))
         | 
| 202 | 
            -
                sig_y += 20
         | 
| 203 | 
            -
             | 
| 204 | 
            -
            qr_pos = (CERT_WIDTH - qr_img.width - MARGIN - 20, CERT_HEIGHT - qr_img.height - MARGIN - 20)
         | 
| 205 | 
            -
            seal_pos = (qr_pos[0], qr_pos[1] - official_seal.height - 15)
         | 
| 206 | 
            -
             | 
| 207 | 
            -
            certificate.paste(official_seal, seal_pos, official_seal)
         | 
| 208 | 
            -
            certificate.paste(qr_img, qr_pos, qr_img)
         | 
| 209 | 
            -
             | 
| 210 | 
            -
            watermarks = [
         | 
| 211 | 
            -
                "AUTHORIZED", "CONFIDENTIAL", "OFFICIAL_USE_ONLY", "SECURE",
         | 
| 212 | 
            -
                "AUTHENTICATED", "NON-TRANSFERABLE", "GOVERNMENT APPROVED", "VERIFIED BY BLOCKCHAIN",
         | 
| 213 | 
            -
                "HIGHLY CONFIDENTIAL", "DIGITAL SIGNED", "SECURE DOCUMENT", "UNIQUE IDENTIFIER",
         | 
| 214 | 
            -
                "ENCRYPTED SEAL",
         | 
| 215 | 
            -
                cert_info["Certificate ID"], verification_code,
         | 
| 216 | 
            -
                "VALIDATED", "NO_COPY", "OPENAI"
         | 
| 217 | 
            -
            ]
         | 
| 218 | 
            -
             | 
| 219 | 
            -
            for _ in range(128):
         | 
| 220 | 
            -
                wm_text = random.choice(watermarks)
         | 
| 221 | 
            -
                txt_img = Image.new("RGBA", (220, 20), (0, 0, 0, 0))
         | 
| 222 | 
            -
                txt_draw = ImageDraw.Draw(txt_img)
         | 
| 223 | 
            -
                txt_draw.text((0, 0), wm_text, font=font_small, fill=WATERMARK_COLOR)
         | 
| 224 | 
            -
                angle = random.uniform(-25, 25)
         | 
| 225 | 
            -
                txt_img = txt_img.rotate(angle, expand=1)
         | 
| 226 | 
            -
                x = random.randint(MARGIN + 10, CERT_WIDTH - 230)
         | 
| 227 | 
            -
                y = random.randint(MARGIN + 10, CERT_HEIGHT - 30)
         | 
| 228 | 
            -
                certificate.paste(txt_img, (x, y), txt_img)
         | 
| 229 | 
            -
             | 
| 230 | 
            -
            pixels = certificate.load()
         | 
| 231 | 
            -
            for _ in range(NOISE_INTENSITY):
         | 
| 232 | 
            -
                px = random.randint(0, CERT_WIDTH - 1)
         | 
| 233 | 
            -
                py = random.randint(0, CERT_HEIGHT - 1)
         | 
| 234 | 
            -
                r, g, b, a = pixels[px, py]
         | 
| 235 | 
            -
                noise = random.randint(-5, 5)
         | 
| 236 | 
            -
                r = max(0, min(255, r + noise))
         | 
| 237 | 
            -
                g = max(0, min(255, g + noise))
         | 
| 238 | 
            -
                b = max(0, min(255, b + noise))
         | 
| 239 | 
            -
                pixels[px, py] = (r, g, b, a)
         | 
| 240 | 
            -
             | 
| 241 | 
            -
            # ======== استگانوگرافی ساده برای درج کد امنیتی پنهان ========
         | 
| 242 | 
            -
            def encode_message_in_pixels(img, message):
         | 
| 243 | 
            -
                binary_message = ''.join(format(ord(i), '08b') for i in message)
         | 
| 244 | 
            -
                pixels = img.load()
         | 
| 245 | 
            -
                width, height = img.size
         | 
| 246 | 
            -
                idx = 0
         | 
| 247 | 
            -
                for y in range(height):
         | 
| 248 | 
            -
                    for x in range(width):
         | 
| 249 | 
            -
                        if idx >= len(binary_message):
         | 
| 250 | 
            -
                            return
         | 
| 251 | 
            -
                        r, g, b, a = pixels[x, y]
         | 
| 252 | 
            -
                        r = (r & ~1) | int(binary_message[idx])
         | 
| 253 | 
            -
                        pixels[x, y] = (r, g, b, a)
         | 
| 254 | 
            -
                        idx += 1
         | 
| 255 | 
            -
             | 
| 256 | 
            -
            hidden_message = f"CertificateID:{cert_info['Certificate ID']};VerificationCode:{verification_code}"
         | 
| 257 | 
            -
            encode_message_in_pixels(certificate, hidden_message)
         | 
| 258 | 
            -
             | 
| 259 | 
            -
            output_file = f"OpenAI_Certificate_{cert_info['Certificate ID']}.png"
         | 
| 260 | 
            -
            certificate.convert("RGB").save(output_file, quality=100)
         | 
| 261 | 
            -
            print(f"✅ Realistic and highly secure certificate created: {output_file}")
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
