Encoding, encryption,
hashing

Encoding

A <=> B

Binary

  • bit vs byte
  • 0 vs 1 is a representation
  • 8bits = 1byte = 256 values (adding length multiplies the space : 7bits = 128 values, + 0 OR 1 is then 256)

Context needed

  • "2018" : Hexa vs ASCII vs Base64
  • Binary : number, text, raw data, ...
  • UTF-8 vs Latin1 (with invalid codepoints)
  • Double vs uint vs int

Different representation, same information

  • Transferability (charset, base64 web vs normal)
  • Lisibility (hashids, intercom names)
  • Weight (hex as UTF8 : 1byte weights 2) 
  • Encoding / decoding on interfaces
  • URL Encoding

Encryption

A => B / B => A

Theorem

  • n = modulo space
  • if e.d  = 1 (mod ϕ(n))
  • then M ^ (e.d) = M (mod n)
  • since M ^ (e.d) = (M ^ e) ^ d = (M ^ d) ^ e (mod n)
  • then C = M ^ e is decryptable by d, n 
  • and C' = M ^ d is decryptable by e, n
  • (d, n) is the private key
  • (e, n) is the public key

Usage

  • Actually symetric key
  • Public/private is convention
  • Key size can be controlled
  • Always generated by pairs

Actual keypair generation

  • choose large primes p, q
  • n = p.q
  • ϕ(n) = (p - 1).(q - 1)
  • choose e < ϕ(n), coprime to ϕ(n)
  • determine d / d.e = 1 (mod ϕ(n))
  • done !

Hashing

A => B

1-way function

  • to fixed length
  • pseudo-random & well distributed
  • deterministic & reproducible

 

 

hash("hello") => 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Crypto vs non-crypto

  • SHA-2x family
  • non-reversible
  • non-generable
  • still fast !

Applications

  • Dicts
  • Grouping w/ modulo (since pseudo-random)
  • Payload verification

Application: Signature

2 goals

  • Message integrity
  • Sender identity

With hashes

  • Shared secret
  • hash (M, secret) => signature
  • hash (M, timestamp, secret) => timed signature

With encryption

  • No shared secret
  • encrypt (hash(M), pubkey) => signature

Questions ?

deck

By David Ruyer

deck

  • 51