<jupyter_start><jupyter_text>(a)<jupyter_code>from termcolor import colored
class Decode:
  def __init__(self, cipher):
    self.cipher = list(map(list, zip(cipher, [0]*len(cipher))))
    self.solved_chars = []

  def print(self):
    to_print = ""
    for i in self.cipher:
      if i[1] == 1:
        # print(colored(i[0], 'green'), end='')
        to_print += colored(i[0], 'green')
      else:
        # print(colored(i[0], 'red'), end='')
        to_print += colored(i[0], 'red')
    print(to_print)

  def replace(self, a, b):
    self.solved_chars.append(b)
    for i in self.cipher:
      if i[1] == 0 and i[0] == a:
        i[0] = b
        i[1] = 1

  def letter_freq(self):
    letters = {}
    for i in self.cipher:
      if i[0] in letters:
        letters[i[0]] += 1
      else:
        letters[i[0]] = 0
    print(letters)

  def getCipher(self):
    c = ""
    for i in self.cipher:
      c = c + i[0]
    return c
c = '''SIDKHKDM AF HCRKIABIE SHIMC KD LFEAILA'''.lower()
decode = Decode(c)
alphabet = "abcdefghijklmnopqrstuvwxyz"
k = "The snow lay thick on the steps and the snowflakes driven by the wind looked black in the headlights of the cars"
#remove space in k
key = k.replace(' ','').lower()
key
#remove repetitive letters from the key
new_key = ""
for i in range(len(key)):
  if key[i] in new_key:
    continue
  else:
    new_key += key[i]
key = new_key
key
i = 0
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 1
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 2
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 3
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 4
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 5
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 6
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 7
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 8
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 9
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 10
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 11
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 12
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 13
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 14
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 15
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 16
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 17
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()
i = 18
print('replacing', alphabet[i], 'with', key[i])
decode.replace(alphabet[i], key[i])
decode.print()<jupyter_output>replacing s with b
[32mb[0m[32ma[0m[32ms[0m[32mi[0m[32ml[0m[32mi[0m[32ms[0m[32mk[0m[31m [0m[32mt[0m[32mo[0m[31m [0m[32ml[0m[32me[0m[32mv[0m[32mi[0m[32ma[0m[32mt[0m[32mh[0m[32ma[0m[32mn[0m[31m [0m[32mb[0m[32ml[0m[32ma[0m[32mk[0m[32me[0m[31m [0m[32mi[0m[32ms[0m[31m [0m[32mc[0m[32mo[0m[32mn[0m[32mt[0m[32ma[0m[32mc[0m[32mt[0m
{'fraction_non_alphanumeric': 0.2198264528004207, 'fraction_numerical': 0.04233499868524849, 'mean_word_length': 5.266886326194399, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '44142', 'license': 'MIT', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1522, 'n_words': 330, 'path': 'Q3_5.ipynb', 'repo_name': 'mowhamadrexa/EECS3481Assignments', 'size': '3803'}