200 likes | 371 Views
Basic Cryptography. Some examples taken from “Coding Theory and Cryptography, the essentials” Second Edition Hankerson, et.al. 2000, Marcel Dekker, Inc Slides by Dannelly. Terms. Plaintext – the readable message Ciphertext – the coded message. Levels of Security.
E N D
Basic Cryptography Some examples taken from “Coding Theory and Cryptography, the essentials” Second Edition Hankerson, et.al. 2000, Marcel Dekker, Inc Slides by Dannelly
Terms • Plaintext – the readable message • Ciphertext – the coded message
Levels of Security • Unconditionally Secure– impossible to break, even if the adversary has unlimited ciphertext and unlimited computing power • Computationally Secure– only infeasible (not impossible) to break the code • Provably Secure– intractable problem
Types of Attacks • Ciphertext Only– adversary uses just the ciphertext to gain either the key or the plaintext (really bad) • Known Plaintext– adversary gets the key using some ciphertext and its plaintext • Chosen Plaintext– adversary introduces some plaintext to generate some ciphertext
Symmetric Key Encryption • Both parties share a key • The single key is used for both encryption and decryption • Encryption and decryption are equal efforts
Shift Ciphers key = amount to shift each character Example: Rotate13 ‘A’ + 13 = 1 + 13 = 14 = ‘N’ So, the message “aardvark” becomes “nneqinex”.
Shift Ciphers Advantage of Rot13: Easy to implement. Rot13('A') = 'N' (1 + 13)%26 = 14 Rot13('N') = 'A' (14 + 13)%26 = 1 So, one function does both encoding and decoding. Disadvantage of Any Rotation: Very easy to break – just try all 26 possibilities.
Substitution Cipher Key = list of character substitutions Example: Key = “Chair” A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Y Z c h a i r B D E F G J K L M N O P Q S T U V W X Disadvantage: Susceptible to Character Frequency Analysis
Polyalphbetic Ciphers Key is repeated and used to shift characters. Example plaintext now is the time for all + key aar dv ark aard var kaa Ciphertext opo mo uzp ujei bpj lmm
Polyalphbetic Ciphers Advantage: Thwarts character frequency analysis. For example, an “e” will encrypt to several different letters. Disadvantage: Statistics can still be used to break the code.
Polyalphbetic Ciphers How to Break Them: 1 - Look for repeated strings. For example, if the characters “thi” appear together frequently, then it could be because the key is hitting a common word. Text = and we need to test and retest Key = ste ve stev es teve ste vestev Sum = thi sj gyjz yh njoy thi njmyxp
Polyalphbetic Ciphers How to Break Them: 2 – Determine Probable Key Length The start of strings “thi” are frequently separated by distances that are multiples of 5. So, key length is probably five. 3A – Try keys of that length. 3B – Use CharFreqAnal on characters separated by that length.
One-Time Pad • Key is used to shift the plaintext. • Key is used only once. • Key has same length as the message. • Advantage: Unbreakable! • Disadvantage: Requires lots of keys.
Hashing • Recall a hash function can be used to "randomly" spread out data and yet still determine where to find data. • For example • hash("steve") = 5, so look in file 5 for steve's data. • hash("bob") = 42, so look in file 42 for bob's data
Sample Hash Function int hash (char[] name) { int sum=0; for (int I=0; I<name.length; I++) sum += name[I]; return sum%tablesize; }
Java's Message Digest • Java provides several hash functions that turn a message into a "message digest". H(msg) = digest • The digest is always the same length, no matter the msg length. • Given a digest, you can not determine either msg or H.
Common Use : verify validity • To Send: • Use a prearranged scheme to determine the Hash function. • Generate message digest from msg. • Send both msg and message digest. • To Verify Received msg: if (Hash(msg) == digest) msg is okay
Sample Code MessageDigest md; byte[] digest; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { return -1; } md.reset(); md.update(first_quarter_of_msg); md.update(forth_quarter_of_msg); md.update(second_quarter_of_msg); md.update(third_quarter_of_msg); digest = md.digest(); This should match the received digest Several Choices of Secure Hash Functions This is the secret part