Академический Документы
Профессиональный Документы
Культура Документы
What I did
The Cryptopals problem set proved to be a challenging yet, extremely insightful
exercise on cryptography. Each of these exercises could warrant a paper onto
themselves, barring XOR-ing bytes, but I would like to focus my writing on a couple of
these encryption algorithms, how they work, and ultimately their use case and how to
break them. With each evolution of difficulty while calling back to previously expressed
knowledge one gets a true appreciation of encryption at a more granular scale. Writing a
paper on this topic solidified my understanding on the topic and having a deeper
knowledge on this one facet of encryption helped me understand each new encryption
method much better.
What I Learned:
XOR Cryptography and Its Implementation (Set 1)
The simplest and perhaps most important subset of cryptography is the bit-wise
XOR. Understand the concepts introduced are expanded and extrapolated on in each of
the following sets. The concept is quite simple but can get a little confusing (personally)
from converting data types from chars to hex to bytes and then preforming bit-wise
operations, glossing over this is not trivial. At its fundamental level, we are translating
ASCII strings to hex to bits and performing a XOR on a ciphertext based on a key of our
choosing. This is illustrated below:
Figure 1:https://en.wikipedia.org/wiki/Base64
Next, to encrypt a message one could use a cipher key and XOR the plaintext to garble
up a message. These can be single or multiple characters. The key will loop across the
length of the plaintext message until the end.
Figure 2: XOR
Now the resulting Cipher could be decoded as a base64, ASCII-256 extended, etc
depending on the preferred bitlength. This procedure was reproduced on set 1-2 and
then a cipher key was guessed and corroborated on set 1-3.
import codecs
def main(): hex_message =
"1c0111001f010100061a024b53535009181c" hex_key =
"686974207468652062756c6c277320657965"
# Convert string to hex
codecs.decode(hex_message, 'hex')
codecs.decode(hex_key, 'hex')
# Convert Hex to byte
byte_message = bytes.fromhex(hex_message)
byte_key = bytes.fromhex(hex_key)
# Logical XOR hashing byte message and byte key xor_encoded =
xor_strings(byte_message, byte_key) xor_encoded.hex()
print(xor_encoded) def xor_strings(hexStringOne, hexStringTwo):
return bytes([b1 ^ b2 for b1, b2 in zip(hexStringOne, hexStringTwo)]) if
__name__ == '__main__': main()
plaintext = singlechar_xor_brute_force(ciphertext)
print_results(plaintext) if __name__ == "__main__":
main()
AES:
AES (Advanced Encryption Standard) uses the Rijndael block cipher algorithm.
Since Rijndael is an iterated block cipher, the encryption or decryption of a block of data
is accomplished by the iteration (a round) of a specific transformation (a round function).
As input, Rijndael accepts one-dimensional 8-bit byte arrays that create data blocks.
The plaintext is input and then mapped onto state bytes. The cipher key is also a one-
dimensional 8-bit byte array. There were several candidate algorithms but Rijndael was
selected because based on the analyses, it had the best combination of security,
performance, efficiency, ease of implementation and flexibility. The Rijndael algorithm
instantiates rounds which are composed of four separate matrix operations: sub bytes,
shift rows, mix columns, and add round key. The general framework is depicted below
on figure 1. We will go into further detail of the function of each of the matrix operators
within each encryption round.
Sub_bytes(): Substituent bytes is called based on the size of the cipher key the number
of iterations required increases.
Shift_rows(): A matrix transform where elements are rotated. The most simple matrix
rotation is shown below:
Citations:
History of cryptography:
[1] http://www.inquiriesjournal.com/articles/1698/a-brief-history-of-cryptography [2]
https://www.cia.gov/news-information/featured-story-archive/2015-featured-
storyarchive/the-enigma-of-alan-turing.html
AES Encryption lecture
[3] https://www.youtube.com/watch?v=4pmR49izUL0
[4] https://csrc.nist.gov/csrc/media/publications/fips/197/final/documents/fips-197.pdf
[5] https://www.cs.mcgill.ca/~kaleigh/computers/crypto_rijndael.html
[6] https://en.wikipedia.org/wiki/Rijndael_S-box
[7] https://homepages.math.uic.edu/~leon/mcs425-s08/handouts/char_freq2.pdf
[8] https://www.statisticshowto.datasciencecentral.com/pareto-principle-the-8020-
rule/
[9] https://en.wikipedia.org/wiki/Advanced_Encryption_Standard#/media/File:AES-
MixColumns.svg