018 Repraesentation III Online
018 Repraesentation III Online
018 Repraesentation III Online
2. Unicode
3. Andere Kodierungen
2
Für die Kommunikation mit Menschen müssen Rechner Zeichen und
Zeichenketten (Strings) verarbeiten können.
5
Historisch bedingte Probleme (2)
String steht Zeichen für Zeichen im Erstes Byte des Strings enthält die
Speicher, gefolgt von NUL (\0 bzw. Länge (0…255), danach folgen
0x00) als Endemarkierung. entsprechend viele Zeichen
Beispiel: Beispiel:
48 61 6c 6c 6f 00 05 48 61 6c 6c 6f
Modernere Sprachen legen Strings als Objekte ab. 8
Inhalt dieser Einheit
2. Unicode
3. Andere Kodierungen
9
Inhalt dieser Einheit
2. Unicode
3. Andere Kodierungen
10
Unicode
Ziel: Einheitliches System für alle Zeichensätze
11
Der Unicode-Standard definiert Symbole für alle bekannten Sprachen und
Kulturen.
Unicode:
Welches Symbol ist gemeint?
Unicode Normalization:
Vereinheitlicht Symbole, die auf
unterschiedliche Weise dargestellt
werden können, z.B. „ü“ als „ü“ oder
Code Point U+1F638 „u“ mit Trema.
GRINNING CAT FACE WITH Encoding: Wie werden Symbole
SMILING EYES gespeichert oder übertragen?
Auszug aus dem Unicode-Standard (C1 Controls and Latin-1 Supplement)
13
Ein Encoding ist eine Vorschrift wie Code-Points in Bytes repräsentiert werden.
Früher Encoding-Vorschlag: UCS-2 (zwei Bytes je Code-Point)
14
Encodings im Zeitverlauf
16
Kodierungsvorschrift bei UTF-8
€
0000 0000 – 0000 007F 0xxxxxxx
0000 0080 – 0000 07FF 110xxxxx 10xxxxxx
0000 0800 – 0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
0001 0000 – 0010 FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
U+20AC
17
Das Encoding muss zusätzlich zur Zeichenkette gespeichert werden, um
Interpretationsfehler zu vermeiden.
Copy-and-Paste
<html>…<body>
😸
</body></html>
19
Besonderheiten im Umgang mit Unicode
20
https://www.xkcd.com/1137/ 21
Das Right-to-Left-Zeichen
https://www.xkcd.com/1137/ 22
Das Right-to-Left-Zeichen
https://www.xkcd.com/1137/ 23
Das Right-to-Left-Zeichen
photo_high_re*U+202E*gnp.js
https://www.xkcd.com/1137/ 24
Weitere Überraschungen in der Praxis
zero-width whitespace
etwa zum Watermarking von Dokumenten
25
… oder um Nutzer zu täuschen
26
https://lifehacker.com/watch-out-for-this-fake-whatsapp-app-in-the-google-play-1820222637 27
Weitere Überraschungen in der Praxis
28
Weitere Überraschungen in der Praxis
Normalisierung
29
Normalisation is very important for
identifiers, such as usernames, to help
people enter values in different ways
but process them consistently. One
common way of normalising
identifiers is to transform everything
into lowercase, making sure that
JamesBond is the same as jamesbond.
https://gojko.net/2017/11/07/five-things-about-unicode.html, https://labs.spotify.com/2013/06/18/creative-usernames/ 30
Normalisation is very important for
identifiers, such as usernames, to help
people enter values in different ways
but process them consistently. One
common way of normalising
identifiers is to transform everything
into lowercase, making sure that
JamesBond is the same as jamesbond.
With so many similar characters and
overlapping sets, different languages
or unicode processing libraries might
apply different normalisation
strategies, potentially opening
security risks if normalisation is done
in several places.
https://gojko.net/2017/11/07/five-things-about-unicode.html, https://labs.spotify.com/2013/06/18/creative-usernames/ 31
Normalisation is very important for In short, don’t assume that lowercase
identifiers, such as usernames, to help transformations work the same in
people enter values in different ways different parts of your application.
but process them consistently. One Mikael Goldmann from Spotify wrote
common way of normalising up a nice incident analysis about this
identifiers is to transform everything issue in 2013, after one of their users
into lowercase, making sure that discovered a way to hijack accounts.
JamesBond is the same as jamesbond.
With so many similar characters and
overlapping sets, different languages
or unicode processing libraries might
apply different normalisation
strategies, potentially opening
security risks if normalisation is done
in several places.
https://gojko.net/2017/11/07/five-things-about-unicode.html, https://labs.spotify.com/2013/06/18/creative-usernames/ 32
Normalisation is very important for In short, don’t assume that lowercase
identifiers, such as usernames, to help transformations work the same in
people enter values in different ways different parts of your application.
but process them consistently. One Mikael Goldmann from Spotify wrote
common way of normalising up a nice incident analysis about this
identifiers is to transform everything issue in 2013, after one of their users
into lowercase, making sure that discovered a way to hijack accounts.
JamesBond is the same as jamesbond. Attackers could register unicode
With so many similar characters and variants of other people’s usernames
overlapping sets, different languages (such as ᴮᴵᴳᴮᴵᴿᴰ), which would be
or unicode processing libraries might translated to the same canonical
apply different normalisation account name (bigbird). Different
strategies, potentially opening layers of the application normalised
security risks if normalisation is done the word differently, allowing people
in several places. to register spoof accounts but reset
the password of the target account.
https://gojko.net/2017/11/07/five-things-about-unicode.html, https://labs.spotify.com/2013/06/18/creative-usernames/ 33
Inhalt dieser Einheit
2. Unicode
Code Points versus Encoding
UCS-2, Byte Order Mark
UTF-8
Right-to-Left
Zero-Width Whitespace
3. Andere Kodierungen
34
Inhalt dieser Einheit
2. Unicode
3. Andere Kodierungen
35
Encodings für andere Zwecke
base64
36
Mit base64 kann man beliebige Bitstrings mit druckbaren Zeichen darstellen:
Zur Kodierung werden jeweils drei Byte in vier 6-Bit-Blöcke aufgeteilt
0 1 2 3 4 … 26 27 28 29 … 57 58 59 60 61 62 63
A B C D E … a b c d … 5 6 7 8 9 + /
Lookup-Tabelle für base64
Um wie viel wird eine Zeichenkette länger, wenn sie
base64-kodiert wird?
38
Encodings für andere Zwecke
base32
39
Encodings für andere Zwecke
base85
40
Inhalt dieser Einheit
2. Unicode
3. Andere Kodierungen
base64 und Varianten
Datenkompression
41
Eine weitere Klasse von Kodierungen dienen der Datenkompression.
WWWWWBBBWWWWWB
5 W 3 B 5 W 1 B (Reduktion um 43%)
Variante:
W W W W W B B B W W W W W B wird zu
WW5BB3WW5B
W B W B W B W W W wird zu W B W B W B W W 3
Bild: http://images17.newegg.com/is/image/newegg/12-423-144-TS?$S640W$ 42
Effizientere Kompression ist mit einem Wörterbuch möglich, etwa wie von
Lempel, Ziv und Welch (LZW) vorgeschlagen (kommt z.B. in GIFs zum Einsatz).
Zeichen Binär Dez.
Erläuterung der Idee am Bsp. von Strings (A–Z).
K 01011 11
Initiales Wörterbuch für A–Z; L 01100 12
ein 5-Bit-Code reicht dafür aus. M 01101 13
Zeichen Binär Dez. N 01110 14
# 00000 0 O 01111 15
A 00001 1 P 10000 16
B 00010 2 Q 10001 17
C 00011 3 R 10010 18
D 00100 4 S 10011 19
E 00101 5 T 10100 20
F 00110 6 U 10101 21
G 00111 7 V 10110 22
H 01000 8 W 10111 23
I 01001 9 X 11000 24
J 01010 10 Y 11001 25
Beispiel aus https://en.wikipedia.org/w/index.php?title=LZW Z 11010 26 43
Wir komprimieren den Text TOBEORNOTTOBEORTOBEORNOT#
2. Unicode
3. Andere Kodierungen
base64 und Varianten
RLE-Verfahren
LZW-Verfahren
45
Nicht in der Vorlesung besprochene Inhalte
aus Kapitel 2 des Skriptums
46