# STL 1 Assignment 2
## 3
```python=
s = data['challenge'][2:]
########################################
ctxt = data['challenge'][2:]
for shift in range(0,128):
l = ''.join([hex(int(i,16)-shift)[2:].zfill(2) for i in [ctxt[i:i+2] for i in range(0,len(ctxt), 2)]])
try:
s = b.unhexlify(l).decode()
if 'dear' in s:
solution = s
except:
pass
########################################
```
After many trials and errors the word `dear` was found to be readable. As such if the word `dear` is found.
## 4
```python=
hex_char_list = [s[i:i+2] for i in range(0,len(s), 2)]
set_char_list = set(hex_char_list)
d = {i:hex_char_list.count(i) for i in set_char_list}
sort_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
d2 = [i[0] for i in sort_d]
keys = [' ','e','t','o','a','h','r','n','d','i','s','l','w','g','u',',','\n','y','c','m','f','p','.','b','v','k','-','j',"'", '?', 'q'] # Most common
pairs = dict(zip(d2,keys))
ans = ''.join(pairs.get(i, i) for i in hex_char_list)
if 'just' not in ans: # This needs to be checked because there may be substitution error since the count is the same
d2[27], d2[28] = d2[28], d2[27]
pairs = dict(zip(d2,keys))
ans = ''.join(pairs.get(i, i) for i in hex_char_list)
```
After many trials and errors the `keys` were found to be so.
## 5
```python=
hex_char_list = [int(a[i:i+2],16) for i in range(0,len(a), 2)]
p = "Student ID 1000000 gets 0 points"
pi = [ord(p[i:i+1]) for i in range(0,len(p))]
xor = [pi[i]^hex_char_list[i] for i in range(len(pi))]
target_p_txt = "Student ID 1003056 gets 6 points"
target_p_txt_i = [ord(target_p_txt[i:i+1]) for i in range(0,len(p))]
h2 = [hex(target_p_txt_i[i]^xor[i])[2:].zfill(2) for i in range(len(target_p_txt_i))]
ans = ''.join(h2)
solution = ans
```
The target ptxt `"Student ID 1003056 gets 6 points"`