<jupyter_start><jupyter_text>TASK 1 - Decrypt text-file  Read file (first 600 words for readability)<jupyter_code>with open("ciphertext_caesar.txt", 'r', encoding="utf8") as file:
    file_content = file.read(600)

print("Encrypted text: \n" + file_content +"\n")<jupyter_output>Encrypted text: 
qfmdhcufodvm, cf qfmdhczcum (tfca obqwsbh ufssy: κρυπτός, fcaobwnsr: yfmdhóg "vwrrsb, gsqfsh"; obr γράφειν ufodvswb, "hc kfwhs", cf -λογία -zcuwo, "ghirm", fsgdsqhwjszm), wg hvs dfoqhwqs obr ghirm ct hsqvbweisg tcf gsqifs qcaaibwqohwcb wb hvs dfsgsbqs ct hvwfr dofhwsg qozzsr orjsfgofwsg. acfs usbsfozzm, qfmdhcufodvm wg opcih qcbghfiqhwbu obr obozmnwbu dfchcqczg hvoh dfsjsbh hvwfr dofhwsg cf hvs dipzwq tfca fsorwbu dfwjohs asggousg; jofwcig ogdsqhg wb wbtcfaohwcb gsqifwhm giqv og roho qcbtwrsbhwozwhm, roho wbhsufwhm, oihvsbhwqohwcb, obr bcb-fsdirwohwcb ofs qsbhfoz hc acrsfb qfmdhcufodvm. acrsfb<jupyter_text>Remove non-letters, count occurence of each letter and sort the dict.<jupyter_code>import collections

freq = {}
for letter in file_content:
    if ord(letter) >= 97 and ord(letter) <= 122:
        if letter not in freq:
            freq.update({letter: 1})
        freq[letter] +=1

sorted_freq = collections.OrderedDict(sorted(freq.items()))
print(sorted_freq)<jupyter_output>OrderedDict([('a', 11), ('b', 36), ('c', 35), ('d', 21), ('e', 2), ('f', 46), ('g', 26), ('h', 46), ('i', 14), ('j', 6), ('k', 2), ('m', 18), ('n', 3), ('o', 41), ('p', 3), ('q', 26), ('r', 21), ('s', 48), ('t', 8), ('u', 14), ('v', 15), ('w', 39), ('y', 3), ('z', 13)])<jupyter_text>Plot occurences of each letter (sorted)<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

fix, ax = plt.subplots()
letters = sorted_freq.keys()
value = sorted_freq.values()
ax.bar(letters, value)
ax.set(xlabel='Letter', ylabel='Count')<jupyter_output><empty_output><jupyter_text>The shift is 12 (looking at similar graphs representing most common english letters)  Decrypt the text-file using the shift found above<jupyter_code>with open("ciphertext_caesar.txt", 'r', encoding="utf8") as file:
    file_line = file.read(600)
    shift = 12
    new_file = ""
    for letter in file_line:
        if ord(letter) >= 97 and (ord(letter) + shift > 122):
            new_file += chr(ord(letter)+shift-26)
        elif ord(letter) >= 97 and (ord(letter) + shift <= 122):
            new_file += chr(ord(letter)+shift)
        else: 
            new_file += letter

print("Decrypted text: \n" + new_file)<jupyter_output>Decrypted text: 
cryptography, or cryptology (from ancient greek: άγηβζξδ, romanized: kryptås "hidden, secret"; and ΥγΞθΧΫί graphein, "to write", or -έαΥΡΣ -logia, "study", respectively), is the practice and study of techniques for secure communication in the presence of third parties called adversaries. more generally, cryptography is about constructing and analyzing protocols that prevent third parties or the public from reading private messages; various aspects in information security such as data confidentiality, data integrity, authentication, and non-repudiation are central to modern cryptography. modern
{'fraction_non_alphanumeric': 0.12960609911054638, 'fraction_numerical': 0.0241423125794155, 'mean_word_length': 4.653500897666068, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '216598', 'license': 'MIT', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1155, 'n_words': 346, 'path': '2.substitution-cipher/21_03_09_task-1_decrypt-textfile.ipynb', 'repo_name': 'henrikforb/DataSecurity-90392', 'size': '3148'}