A sender (traditionally called Alice) would like to send a message to a receiver (traditionally, Bob).
However, while the message is being sent, it can be observed by an eavesdropper (Eve), and Bob and Alice would like to hide it’s meaning from Eve.
For example, Alice wants to send the following message:
mysnapchatusernameisramblingscrambler
Instead, she sends the message:
oaupcrejcvwugtpcogkutcodnkpiuetcodngt
Discuss. Eve observes this communication, and figures out their encryption scheme. The next message sent is
qnffqi
. What is the decrypted message? What is Alice and Bob’s scheme?
Coding Theory deals with how we represent information digitally.
Syllabus (PDF)
Assumption: Eve always knows the method Alice and Bob are using.
olddog
)qnffqi
)Example. The method described above is called a shift cipher (or Caesar cipher).
olddog
qnffqi
2
(how much to shift)Question: How do you encrypt the plaintext
fuzzy
?
We write \[a \equiv b \pmod n\] to denote that \(a\) and \(b\) belong to the same equivalence class modulo \(n\); that is, \((a-b)\) is a multiple of \(n\).
We write \(n \bmod m\) to represent the remainder when \(n\) is divided by \(m\). For example, in R, we compute \(38 \bmod 6\) as follows.
[1] 2
Since \(38 \bmod 6 = 2\), \(38\) and \(2\) are in the same equivalence class modulo \(6\), which we denote as \[38 \equiv 2 \pmod 6\] or equivalently, as \[2 \equiv 38 \pmod 6\]
Theorem. If \(a \equiv b \pmod n\) and \(c \equiv d \pmod n\), then:
In other words, when you do arithmetic modulo \(n\), it doesn’t matter which equivalence class representatives you use. In terms of operators, you can apply the \(\bmod\) operator before or after adding and multiplying, and you will obtain the same result. (Example.)
Compute each expression modulo 7, without using technology.
\((32 + 76)(144 - 7000) \bmod 7\)
\(23^{100} \bmod 7\)
(Take a look at this problem in RStudio.)
What goes wrong here?
Warning: probable complete loss of accuracy in modulus
[1] 0
Big Integer ('bigz') :
[1] 14886191506363039393791556586559754231987119653801368686576988209222433278539331352152390143277346804233476592179447310859520222529876001
Big Integer ('bigz') :
[1] 2
Instead of exponentiating and then modding, we can use the
gmp::powm
function, which is more efficient.
Big Integer ('bigz') :
[1] 2
[1] 46 90 134
[1] 20 40 60
utf8ToInt
[1] 65
[1] 65 80 80 76 69
[1] "APPLE"
stringToMod26 <- function(x) {utf8ToInt(x)-utf8ToInt("a")}
mod26ToString <- function(x) {intToUtf8(x+utf8ToInt("a"))}
shiftCipher <- function(p,b)
{
pt <- stringToMod26(p)
ct <- (pt + b) %% 26 # add b to each letter
return(mod26ToString(ct))
}
shiftCipher("thisisasecretmessage", 2)
[1] "vjkukucugetgvoguucig"
[1] "melcgsx"
[1] "cubswin"
[1] "cubswin"
In a ciphertext only attack, Eve has only the ciphertext and wishes to decrypt it and obtain the key.
[1] "vgflxgjywllgvglzwskkayfewflk"
[1] "whgmyhkzxmmhwhmaxtllbzgfxgml"
[1] "xihnzilaynnixinbyummcahgyhnm"
[1] "yjioajmbzoojyjoczvnndbihzion"
[1] "zkjpbkncappkzkpdawooecjiajpo"
[1] "alkqclodbqqlalqebxppfdkjbkqp"
[1] "bmlrdmpecrrmbmrfcyqqgelkclrq"
[1] "cnmsenqfdssncnsgdzrrhfmldmsr"
[1] "dontforgettodotheassignments"
[1] "epougpshfuupepuifbttjhonfout"
[1] "fqpvhqtigvvqfqvjgcuukipogpvu"
[1] "grqwirujhwwrgrwkhdvvljqphqwv"
[1] "hsrxjsvkixxshsxliewwmkrqirxw"
[1] "itsyktwljyytitymjfxxnlsrjsyx"
[1] "jutzluxmkzzujuznkgyyomtsktzy"
[1] "kvuamvynlaavkvaolhzzpnutluaz"
[1] "lwvbnwzombbwlwbpmiaaqovumvba"
[1] "mxwcoxapnccxmxcqnjbbrpwvnwcb"
[1] "nyxdpybqoddynydrokccsqxwoxdc"
[1] "ozyeqzcrpeezozesplddtryxpyed"
[1] "pazfradsqffapaftqmeeuszyqzfe"
[1] "qbagsbetrggbqbgurnffvtazragf"
[1] "rcbhtcfushhcrchvsoggwubasbhg"
[1] "sdciudgvtiidsdiwtphhxvcbtcih"
[1] "tedjvehwujjetejxuqiiywdcudji"
[1] "ufekwfixvkkfufkyvrjjzxedvekj"
sapply
[1] "vgflxgjywllgvglzwskkayfewflk" "whgmyhkzxmmhwhmaxtllbzgfxgml"
[3] "xihnzilaynnixinbyummcahgyhnm" "yjioajmbzoojyjoczvnndbihzion"
[5] "zkjpbkncappkzkpdawooecjiajpo" "alkqclodbqqlalqebxppfdkjbkqp"
[7] "bmlrdmpecrrmbmrfcyqqgelkclrq" "cnmsenqfdssncnsgdzrrhfmldmsr"
[9] "dontforgettodotheassignments" "epougpshfuupepuifbttjhonfout"
[11] "fqpvhqtigvvqfqvjgcuukipogpvu" "grqwirujhwwrgrwkhdvvljqphqwv"
[13] "hsrxjsvkixxshsxliewwmkrqirxw" "itsyktwljyytitymjfxxnlsrjsyx"
[15] "jutzluxmkzzujuznkgyyomtsktzy" "kvuamvynlaavkvaolhzzpnutluaz"
[17] "lwvbnwzombbwlwbpmiaaqovumvba" "mxwcoxapnccxmxcqnjbbrpwvnwcb"
[19] "nyxdpybqoddynydrokccsqxwoxdc" "ozyeqzcrpeezozesplddtryxpyed"
[21] "pazfradsqffapaftqmeeuszyqzfe" "qbagsbetrggbqbgurnffvtazragf"
[23] "rcbhtcfushhcrchvsoggwubasbhg" "sdciudgvtiidsdiwtphhxvcbtcih"
[25] "tedjvehwujjetejxuqiiywdcudji" "ufekwfixvkkfufkyvrjjzxedvekj"
In a known plaintext attack, Eve has a plaintext string along with the corresponding ciphertext, and wishes to recover the key.
plaintext <- "usecanvas"
ciphertext <- "camkivdia"
(stringToMod26(ciphertext)-stringToMod26(plaintext)) %% 26
[1] 8 8 8 8 8 8 8 8 8
In a chosen plaintext attack, Eve temporarily gets access to the “encryption machine”, and encrypts a plaintext message of her choosing, observing the ciphertext.
[1] 7
In a chosen ciphertext attack, Eve temporarily gets access to the “decryption machine”, and decrypts a ciphertext message of her choosing, observing the plaintext.
[1] 7
gmp
and test some of the examples from these notes.