<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=Advanced_Python_%28Fall_2017%29%2Flecture10</id>
	<title>Advanced Python (Fall 2017)/lecture10 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=Advanced_Python_%28Fall_2017%29%2Flecture10"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture10&amp;action=history"/>
	<updated>2026-06-21T22:57:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture10&amp;diff=126801&amp;oldid=prev</id>
		<title>Eroman: Created page with &quot;= Lecture 10 =  Cryptopals  https://cryptopals.com/  Many solution here: https://www.google.ee/search?dcr=0&amp;amp;source=hp&amp;amp;ei=k-oCWtGxJaHg6ASl0a4g&amp;amp;q=cryptopals+solution...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=Advanced_Python_(Fall_2017)/lecture10&amp;diff=126801&amp;oldid=prev"/>
		<updated>2017-11-14T08:26:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Lecture 10 =  Cryptopals  https://cryptopals.com/  Many solution here: https://www.google.ee/search?dcr=0&amp;amp;source=hp&amp;amp;ei=k-oCWtGxJaHg6ASl0a4g&amp;amp;q=cryptopals+solution...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Lecture 10 =&lt;br /&gt;
&lt;br /&gt;
Cryptopals&lt;br /&gt;
&lt;br /&gt;
https://cryptopals.com/&lt;br /&gt;
&lt;br /&gt;
Many solution here: https://www.google.ee/search?dcr=0&amp;amp;amp;source=hp&amp;amp;amp;ei=k-oCWtGxJaHg6ASl0a4g&amp;amp;amp;q=cryptopals+solutions+python&amp;amp;amp;oq=cryptopals+solutions+p&amp;amp;amp;gs_l=psy-ab.3.0.0i19k1.657.4332.0.4870.17.16.1.0.0.0.124.1236.14j2.16.0....0...1.1.64.psy-ab..0.17.1235...0j0i131k1j0i22i30i19k1j33i21k1j33i160k1.0.IM86h-JeYBc&lt;br /&gt;
&lt;br /&gt;
Very good solutions here (better than mine): https://github.com/ricpacca/cryptopals&lt;br /&gt;
&lt;br /&gt;
== Binary, Hex, Base64 ==&lt;br /&gt;
&lt;br /&gt;
Look them up if you don&amp;#039;t know what they are. Unfortanetly, I cannot find a very good introduction to the topics in python.&lt;br /&gt;
&lt;br /&gt;
In python you have integer literals in base 10, like &amp;lt;code&amp;gt;10&amp;lt;/code&amp;gt; or in base 16, like &amp;lt;code&amp;gt;0xf&amp;lt;/code&amp;gt; or in base 2, like &amp;lt;code&amp;gt;0b1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Binary numbers can easily be representing in base 16 (called &amp;amp;quot;Hex&amp;amp;quot;). 8 bits (binary digits) is 2 digits in hex. Base64 is a way of storing binary data so it uses only ascii characters. A string of Base64 is shorter than a string of equivalent Hex, so Base64 is popular way to put binary data embeded in a text document.&lt;br /&gt;
&lt;br /&gt;
== Problems ==&lt;br /&gt;
&lt;br /&gt;
The problems are good because they require us to understand encoding in python. My solutions are poorer quality in comparison to the solutions here: https://github.com/ricpacca/cryptopals&lt;br /&gt;
&lt;br /&gt;
== Problem 1-1 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;import base64&lt;br /&gt;
&lt;br /&gt;
message_hex = &amp;quot;49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d&amp;quot;&lt;br /&gt;
message_bytes = bytearray.fromhex(message_hex)&lt;br /&gt;
message_base64 = base64.encodebytes(message_bytes)&lt;br /&gt;
print(message_base64)&amp;lt;/source&amp;gt;&lt;br /&gt;
== Problem 1-2 ==&lt;br /&gt;
&lt;br /&gt;
one way&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;# Convert both hex string to bytes&lt;br /&gt;
hex_string_1 = &amp;#039;1c0111001f010100061a024b53535009181c&amp;#039;&lt;br /&gt;
hex_string_2 = &amp;#039;686974207468652062756c6c277320657965&amp;#039;&lt;br /&gt;
&lt;br /&gt;
bytes_1 = bytearray.fromhex(hex_string_1)&lt;br /&gt;
bytes_2 = bytearray.fromhex(hex_string_2)&lt;br /&gt;
&lt;br /&gt;
# Pair each byte with other byte in same position&lt;br /&gt;
byte_pair_list = list(zip(bytes_1, bytes_2))&lt;br /&gt;
&lt;br /&gt;
# go through each bit in hex string bytes, and xor, and store result&lt;br /&gt;
# XOR opertator is ^&lt;br /&gt;
result_list = []&lt;br /&gt;
for b1, b2 in byte_pair_list:&lt;br /&gt;
    xor_result = b1 ^ b2&lt;br /&gt;
    result_list.append(xor_result)&lt;br /&gt;
&lt;br /&gt;
# convert list of integers to hex&lt;br /&gt;
result_bytes = bytearray(result_list)&lt;br /&gt;
print(bytearray.hex(result_bytes))&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eroman</name></author>
	</entry>
</feed>