Hashing and digital signatures · Hachage et signatures numériques
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.
Le hachage protège l'intégrité
- Nous avons haché les mots de passe pour la confidentialité. Le hachage protège aussi l'intégrité — prouver que les données n'ont pas été modifiées.
- Changez même un seul caractère de l'entrée, et le hachage change complètement.
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.
Vérifier un téléchargement
- Les sites publient le hachage d'un fichier. Après téléchargement, vous hachez votre copie et comparez.
- Si les deux hachages correspondent, le fichier est arrivé intact. Sinon, il a été corrompu ou altéré.
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.
Signatures numériques
- Une signature numérique prouve qui a envoyé quelque chose et qu'il n'a pas été modifié.
- L'expéditeur hache le message et chiffre ce hachage avec sa clé privée.
- N'importe qui peut le vérifier avec la clé publique de l'expéditeur — seul le vrai expéditeur aurait pu le créer.
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).
À vous
- Comparez les hachages d'un message original et reçu.
Truesignifie que le message est intact.
Couvre : A-Level 17.1 (certification numérique), 6.2 (intégrité).
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.
Erreurs courantes
- Un hachage est un sens — vous ne pouvez pas obtenir l'original depuis celui-ci.
- Une signature numérique prouve qui a envoyé un message et qu'il n'a pas été modifié.
Hashing & signatures · Hachage et signatures
A hash is one-way and · et avalanches — perfect for fingerprints. · Un hash est irréversible et s'amplifie — parfait pour les empreintes digitales.
Check whether a received message is unchanged. Hash both original and · et received with SHA-256 and print whether the two digests are equal (True or · ou False). · Vérifiez si un message reçu est inchangé. Hachez les deux original et received avec SHA-256 et print si les deux digests sont égaux (True ou False).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
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. · Cette fois, un attaquant a modifié le message en transit. Hachez les deux versions et imprimez TAMPERED si les digests diffèrent, sinon OK — un seul caractère changé suffit à attraper.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.