Hashing and digital signatures · التجزئة والتواقيع الرقمية
Hashing protects integrity
- We hashed passwords for secrecy. Hashing also protects integrity — proving data was not changed.
- Change even one character of the input, and the hash changes completely.
التجزئة تحمي النزاهة
- قمنا بتجزئة كلمات المرور من أجل السرية. التجزئة تحمي أيضاً النزاهة — إثبات أن البيانات لم تتغير.
- تغيير حرف واحد فقط في المدخلات، وتتغير التجزئة بالكامل.
import hashlib
print(hashlib.sha256(b"hello").hexdigest()[:16])
print(hashlib.sha256(b"hellp").hexdigest()[:16]) # totally different
Checking a download
- Websites publish the hash of a file. After downloading, you hash your copy and compare.
- If the two hashes match, the file arrived intact. If not, it was corrupted or tampered with.
التحقق من التحميل
- تنشر المواقع تجزئة الملف. بعد التحميل، تقوم بتجزئة نسختك وتقارنها.
- إذا تطابقت التجزئتان، وصل الملف بشكل سليم. وإلا، فقد تعرض للتلف أو التعديل.
Digital signatures
- A digital signature proves who sent something and that it was not changed.
- The sender hashes the message and encrypts that hash with their private key.
- Anyone can check it with the sender's public key — only the real sender could have made it.
التواقيع الرقمية
- التوقيع الرقمي يثبت من أرسل شيئاً وأنه لم يتغير.
- يقوم المرسل بتجزئة الرسالة ثم يشفر تلك التجزئة بـمفتاحه الخاص.
- يمكن لأي شخص التحقق منها باستخدام مفتاحه العام — فقط المرسل الحقيقي هو من استطاع إنشائها.
Your turn
- Compare the hashes of an original and a received message.
Truemeans the message is intact.
Covers: A-Level 17.1 (digital certification), 6.2 (integrity).
دورك الآن
- قارن تجزئات الأصل والرسالة المستقبلة.
Trueيعني أن الرسالة سليمة.
يغطي: A-Level 17.1 (الشهادة الرقمية)، 6.2 (النزاهة).
Common mistakes
- A hash is one-way — you cannot get the original back from it.
- A digital signature proves who sent a message and that it was not changed.
أخطاء شائعة
- التجزاة ذات اتجاه واحد — لا يمكنك استعادة الأصل منها.
- التوقيع الرقمي يثبت من أرسل رسالة وأن هذه لم تتغير.
Hashing & signatures · التجزئة والتواقيع
A hash is one-way and avalanches — perfect for fingerprints. · التجزئة عملية ذات اتجاه واحد ومتضخمة — مثالية للبصمات.
Check whether a received message is unchanged. Hash both original and received with SHA-256 and print whether the two digests are equal (True or False). · تحقق من أن رسالة مستلمة لم تتغير. احسب التجزئة لكلا original وreceived باستخدام SHA-256، ثم print ما إذا كانت الهاشتان متساويتان (True أو False).
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
This time an attacker edited the message in transit. Hash both versions and print TAMPERED if the digests differ, else OK — one changed character is enough to catch. · هذه المرة عدّل مهاجم الرسالة أثناء النقل. احسب التجزئة للنسختين وا-print TAMPERED إذا اختلفت الهاشتان، وإلا اطبع OK — تغيير حرف واحد يكفي للكشف.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.