CoolFace
Datasetpublic

ysn-rfd/text-dataset-tiny-code-script-py-format

USED of tahamajs/medicine_ds_persian for .parquet file USED of Alijafarixcs2/persian-it-llama2-2k for .parquet file USED of Abirate/english_quotes for .jsonl file NEW FILES (05/12/2025) NEW FILES (12/26/2025) NEW FILES (02/15/2026)

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
3likes1.6kdownloads
cert13.py162 linesDownload Raw Back to cert
1from PIL import Image, ImageDraw, ImageFont, ImageFilter
2import qrcode
3import hashlib
4import random
5import math
6import os
7import base64
8
9from cryptography.hazmat.primitives.asymmetric import rsa, padding
10from cryptography.hazmat.primitives import hashes, serialization
11
12# تنظیمات
13CERT_WIDTH, CERT_HEIGHT = 900, 650
14MARGIN = 30
15BACKGROUND_COLOR = (255, 255, 250)
16TITLE_COLOR = (20, 20, 20)
17TEXT_COLOR = (40, 40, 40)
18WATERMARK_COLOR = (60, 60, 60, 25)
19NOISE_INTENSITY = 10000
20
21# اطلاعات گواهی
22cert_info = {
23    "Name": "Yasin",
24    "Last Name": "Aryanfard",
25    "User ID": "YSNRFD",
26    "Membership Date": "April 1, 2023",
27    "Issued Date": "June 28, 2025",
28    "Certificate ID": "OPENAI-YSN-APR2023-CERT1001",
29    "Signed By": "ChatGPT-4o",
30    "Model ID": "GPT4O-REP-TRUST-2025",
31    "Issuer": "OpenAI, Inc."
32}
33
34# ساخت کلیدهای RSA
35def generate_rsa_keys():
36    private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
37    public_key = private_key.public_key()
38    return private_key, public_key
39
40# ذخیره کلیدها
41def save_rsa_keys(private_key, public_key):
42    with open("private_key.pem", "wb") as f:
43        f.write(private_key.private_bytes(
44            encoding=serialization.Encoding.PEM,
45            format=serialization.PrivateFormat.TraditionalOpenSSL,
46            encryption_algorithm=serialization.NoEncryption()
47        ))
48    with open("public_key.pem", "wb") as f:
49        f.write(public_key.public_bytes(
50            encoding=serialization.Encoding.PEM,
51            format=serialization.PublicFormat.SubjectPublicKeyInfo
52        ))
53
54# بارگذاری فونت ساده (می‌توان پیشرفته‌تر کرد)
55def load_font(name, size):
56    paths = [
57        name,
58        os.path.join("/usr/share/fonts/truetype/dejavu/", name),
59        os.path.join("/Library/Fonts/", name),
60        os.path.join("C:/Windows/Fonts/", name)
61    ]
62    for path in paths:
63        try:
64            return ImageFont.truetype(path, size)
65        except:
66            continue
67    return ImageFont.load_default()
68
69font_title = load_font("timesbd.ttf", 36)
70font_text = load_font("times.ttf", 18)
71font_small = load_font("times.ttf", 14)
72
73# ساخت گرادیانت پس‌زمینه
74def draw_gradient(draw, width, height, start_color, end_color):
75    for i in range(height):
76        r = int(start_color[0] + (float(i) / height) * (end_color[0] - start_color[0]))
77        g = int(start_color[1] + (float(i) / height) * (end_color[1] - start_color[1]))
78        b = int(start_color[2] + (float(i) / height) * (end_color[2] - start_color[2]))
79        draw.line([(0, i), (width, i)], fill=(r, g, b))
80
81# ساخت QR code
82def create_qr_code(data, size=180):
83    qr = qrcode.QRCode(box_size=8, border=3)
84    qr.add_data(data)
85    qr.make(fit=True)
86    qr_img = qr.make_image(fill_color="#003366", back_color="white").convert("RGBA")
87    qr_img = qr_img.resize((size, size), Image.Resampling.LANCZOS)
88    return qr_img
89
90def encode_message_in_pixels(img, message):
91    binary_message = ''.join(format(ord(i), '08b') for i in message)
92    pixels = img.load()
93    width, height = img.size
94    idx = 0
95    for y in range(height):
96        for x in range(width):
97            if idx >= len(binary_message):
98                return
99            r, g, b, a = pixels[x, y]
100            r = (r & ~1) | int(binary_message[idx])
101            pixels[x, y] = (r, g, b, a)
102            idx += 1
103
104def main():
105    private_key, public_key = generate_rsa_keys()
106    save_rsa_keys(private_key, public_key)
107
108    # داده‌های برای امضا
109    data_string = "\n".join(f"{k}: {v}" for k, v in cert_info.items()).encode('utf-8')
110
111    digital_signature_bytes = private_key.sign(
112        data_string,
113        padding.PSS(
114            mgf=padding.MGF1(hashes.SHA256()),
115            salt_length=padding.PSS.MAX_LENGTH
116        ),
117        hashes.SHA256()
118    )
119    digital_signature = base64.b64encode(digital_signature_bytes).decode('utf-8')
120    verification_code = f"VER-{hashlib.sha256(data_string).hexdigest()[:8].upper()}-{cert_info['Certificate ID'][-4:]}"
121
122    qr_img = create_qr_code(digital_signature, size=180)
123
124    certificate = Image.new("RGBA", (CERT_WIDTH, CERT_HEIGHT), BACKGROUND_COLOR)
125    draw = ImageDraw.Draw(certificate)
126    draw_gradient(draw, CERT_WIDTH, CERT_HEIGHT, (255, 255, 250), (220, 230, 255))
127
128    title_text = "OpenAI – Certificate of Membership"
129    w, h = draw.textsize(title_text, font=font_title)
130    draw.text(((CERT_WIDTH - w) / 2, MARGIN + 10), title_text, fill=TITLE_COLOR, font=font_title)
131
132    info_x, info_y = MARGIN + 30, MARGIN + 70
133    line_spacing = 36
134    for key, val in cert_info.items():
135        text_line = f"{key}: {val}"
136        draw.text((info_x, info_y), text_line, font=font_text, fill=TEXT_COLOR)
137        info_y += line_spacing
138
139    verification_label = "Verification Code:"
140    draw.text((info_x, info_y + 20), verification_label, font=font_text, fill=TEXT_COLOR)
141    draw.text((info_x + 190, info_y + 20), verification_code, font=font_text, fill=(0, 70, 120))
142
143    sig_lines = [digital_signature[i:i+60] for i in range(0, len(digital_signature), 60)]
144    sig_y = info_y + 60
145    for line in sig_lines:
146        draw.text((info_x, sig_y), line, font=font_small, fill=(100, 100, 120))
147        sig_y += 20
148
149    qr_pos = (CERT_WIDTH - qr_img.width - MARGIN - 20, CERT_HEIGHT - qr_img.height - MARGIN - 20)
150    certificate.paste(qr_img, qr_pos, qr_img)
151
152    # درج پیام مخفی استگانوگرافی (CertificateID و VerificationCode)
153    hidden_message = f"CertificateID:{cert_info['Certificate ID']};VerificationCode:{verification_code}"
154    encode_message_in_pixels(certificate, hidden_message)
155
156    output_file = "openai_certificate_yasin_realistic2.png"
157    certificate.convert("RGB").save(output_file, quality=95)
158    print(f"✅ Certificate created and saved as: {output_file}")
159
160if __name__ == "__main__":
161    main()
162