예제 #1
0
def task12():
    filename = 'images/im5_vigener_cfb_c_all.bmp'
    cipher_data = read(filename)
    key = [ord(ch) for ch in 'MONARCH']
    iv = 172
    res = cfb_decrypt(cipher_data, iv, key, type='vigenere')
    write('decrypted_images/task12.bmp', res)
예제 #2
0
def task10():
    filename = 'images/z5_vigener_cbc_c_all.bmp'
    cipher_data = read(filename)
    key = [ord(ch) for ch in 'MODELING']
    iv = 67
    decrypted = cbc_decrypt(cipher_data, iv, key, type='vigenere')
    write('decrypted_images/task10.bmp', decrypted)
예제 #3
0
def task7():
    filename = 'images/z2_caesar_cfb_c_all.bmp'
    cipher_data = read(filename)
    iv = 9
    key = 174
    decrypted = cfb_decrypt(cipher_data, iv, key, type='caesar')
    write('decrypted_images/task7.bmp', decrypted)
예제 #4
0
def task5():
    a = 19
    b = 236
    a_inv = find_mod_inverse(a, 256)
    encrypted_bmp_data = read('./imgs/ff2_affine_c_all.bmp')
    decrypted_bmp_data = affine.decrypt_data(encrypted_bmp_data, a_inv, b)
    write('./imgs/task5_decrypted.BMP', decrypted_bmp_data)
예제 #5
0
def task16():
    filename = 'images/im17_affine_сfb_c_all.bmp'
    cipher_data = read(filename)
    key = {'a': 117, 'b': 239}
    iv = 19
    decrypted = cfb_decrypt(cipher_data, iv, key, type='affine')
    write('decrypted_images/task16.bmp', decrypted)
예제 #6
0
def task17():
    filename = 'images/z4_affine_сtr_c_all.bmp'
    cipher_data = read(filename)
    key = {'a': 61, 'b': 18}
    iv = 92
    decrypted = ctr_decrypt(cipher_data, iv, key, 'affine')
    write('decrypted_images/task17.bmp', decrypted)
예제 #7
0
def task15():
    filename = 'images/im16_affine_ofb_c_all.bmp'
    cipher_data = read(filename)
    key = {'a': 233, 'b': 216}
    iv = 141
    decrypted = ofb_decrypt(cipher_data, iv, key, type='affine')
    write('decrypted_images/task15.bmp', decrypted)
예제 #8
0
def task14():
    filename = 'images/im15_affine_cbc_c_all.bmp'
    cipher_data = read(filename)
    key = {'a': 129, 'b': 107}
    iv = 243
    decrypted = cbc_decrypt(cipher_data, iv, key, type='affine')
    write('decrypted_images/task14.bmp', decrypted)
예제 #9
0
def task13():
    filename = 'images/z6_vigener_ctr_c_all.bmp'
    cipher_data = read(filename)
    key = [ord(ch) for ch in 'MONOLITH']
    iv = 167
    res = ctr_decrypt(cipher_data, iv, key, 'vigenere')
    write('decrypted_images/task13.bmp', res)
예제 #10
0
def task11():
    filename = 'images/im4_vigener_ofb_c_all.bmp'
    cipher_data = read(filename)
    key = [ord(ch) for ch in 'MODULATOR']
    iv = 217
    res = ofb_decrypt(cipher_data, iv, key, type='vigenere')
    write('decrypted_images/task11.bmp', res)
예제 #11
0
def task2():
    encrypted_img_data = read('./imgs/c4_caesar_c_all.bmp')
    for key in range(256):
        decrypted = Caesar.decrypt_data(encrypted_img_data[:2], key)
        if decrypted == [66, 77]:
            print(f'Key is {key}')
            break
    decrypted_bmp = Caesar.decrypt_data(encrypted_img_data, key)
    write('./imgs/task2_decrypted_bmp.BMP', decrypted_bmp)
예제 #12
0
def task1():
    encrypted_data = read('./text_files/t3_caesar_c_all.txt')
    for key in range(256):
        decrypted = Caesar.decrypt_data(encrypted_data[:25], key)
        txt = ''.join(chr(ch) for ch in decrypted)
        if isEnglish(txt):
            break
    decrypted_data = Caesar.decrypt_data(encrypted_data, key)
    write('./text_files/task1_decrypted.txt', decrypted_data)
예제 #13
0
def decode(filename, output_name, key):
    encrypted_data = read(filename)
    inv_key = find_inverse_key(key)
    decrypted_data = []
    for i in range(0, len(encrypted_data), 2):
        d = np.array([encrypted_data[i], encrypted_data[i+1]])
        decrypted = np.matmul(inv_key, d) % ALPHABET_SIZE
        decrypted_data += list(decrypted)
    write(output_name, data=decrypted_data)
예제 #14
0
def save_top_words (info,dir_name):
    for group_name,group_words in info.iteritems():
        content = []
        words_sorted = sorted (group_words.iteritems(), key=operator.itemgetter(1), reverse=True)   
        i=0
        for k,v in words_sorted:
            content.append ('%s %d' % (k,v))
            i += 1
        filename = group_name + '_' + str(i)+ '_statics.txt'
        filename = os.path.join (dir_name, filename)
        read_write_file.write (filename, '\n'.join(content))
예제 #15
0
def task9():
    data = read('decrypted_images/task5.bmp')
    key = 223
    iv = 78
    encrypted_data_ecb = caesar.encrypt_data(data, key, thr=50)
    write('task9_ecb.bmp', encrypted_data_ecb)
    encrypted_data_ofb = ofb_encrypt(data, iv, key, type='caesar', thr=50)
    write('task9_ofb.bmp', encrypted_data_ofb)
    encrypted_data_cfb = cfb_encrypt(data, iv, key, type='caesar', thr=50)
    write('task9_cfb.bmp', encrypted_data_cfb)
    encrypted_data_cbc = cbc_encrypt(data, iv, key, type='caesar', thr=50)
    write('task9_cbc.bmp', encrypted_data_cbc)
    encrypted_data_ctr = ctr_encrypt(data, iv, key, type='caesar', thr=50)
    write('task9_ctr.bmp', encrypted_data_ctr)
예제 #16
0
def main():
    print('\nFor copy-paste convenience, \ndouble-click and copy:\n')
    show_PDFs_in_current_directory()

    file_name = file_prompt()

    page_texts = get_page_texts_in_pdf(file_name)

    write('backup.txt', '\n'.join(page_texts))
    txt_string = read('backup.txt')

    lines = txt_string.split('\n')

    hst_lines = []
    rebate_lines = []
    total_lines = []
    month = ''
    for index, line in enumerate(lines):
        month = get_month(lines, index, line)
        if month:
            hst_lines.append(month)
            rebate_lines.append(month)
            total_lines.append(month)

        hst_util = 'HST on Gas '
        hst_hydro = 'Harmonized Sales Tax on $'
        hst_hydro_new = 'HST ('
        if hst_util in line or hst_hydro in line or hst_hydro_new in line:
            # HST
            hst_lines.append(get_number_at_end_of_line(line))

        rebate_hydro = 'Electricity Rebate'
        if rebate_hydro in line:
            # rebate
            rebate_lines.append(get_credit_at_end_of_line(line))

        total_util_g_w = 'Total Gas & Water Charges'
        total_util_s = 'Total  Stormwater Rate Charges'
        if total_util_g_w in line:
            # total, including HST
            total_lines.append('GW ' + get_number_at_end_of_line(line))
        if total_util_s in line:
            # total, including HST
            total_lines.append(' S ' + get_number_at_end_of_line(line))

        total_hydro = 'PAYABLEONOR'  # always line above
        total_hydro_new = 'What Do I Owe?'  # always line above
        if total_hydro in line or total_hydro_new in line:
            # total, including HST
            next_line = lines[index + 1]
            total_lines.append(get_total_for_hydro_new(next_line))

    write('_hst.txt', '\n'.join(hst_lines))
    write('_rebate.txt', '\n'.join(rebate_lines))
    write('_total.txt', '\n'.join(total_lines))
예제 #17
0
def task7():
    encrypted_png_data = read('./imgs/b4_affine_c_all.png')
    count = 0
    keys = None
    for a in range(256):
        if keys:
            break
        for b in range(256):
            if gcd(a, 256) == 1:
                a_inv = find_mod_inverse(a, 256)
                if a_inv is None:
                    continue
                count += 1
                decrypted_data = affine.decrypt_data(encrypted_png_data[:2],
                                                     a_inv, b)
                if decrypted_data == [137, 80]:
                    print(f'Keys are: a={a}, b={b}, Attempts: {count}')
                    keys = [a, b]
    a, b = keys
    decrypted_png_data = affine.decrypt_data(encrypted_png_data,
                                             find_mod_inverse(a, 256), b)
    write('./imgs/task7_decrypted.png', decrypted_png_data)
예제 #18
0
def task6():
    filename = 'images/im8_caesar_ofb_c_all.bmp'
    key = 56
    iv = 9
    cipher_data = read(filename)
    decrypted = ofb_decrypt(cipher_data, iv, key, type='caesar')
    write('decrypted_images/task6.bmp', decrypted)
    # ofb encryption
    data = read('decrypted_images/task6.bmp')
    encrypted = ofb_encrypt(data, iv, key, type='caesar', thr=50)
    write('decrypted_images/task6_ofb_50.bmp', encrypted)
    # # ecb encryption
    encrypted = caesar.encrypt_data(data, key, thr=50)
    write('decrypted_images/task6_ecb_50.bmp', encrypted)
예제 #19
0
def task8():
    filename = 'images/z3_caesar_ctr_c_all.bmp'
    cipher_data = read(filename)
    key = 223
    iv = 78
    decrypted = ctr_decrypt(cipher_data, iv, key, 'caesar')
    write('decrypted_images/task8.bmp', decrypted)
    # encr ctr
    data = read('decrypted_images/task8.bmp')
    encrypted = ctr_encrypt(data, iv, key, 'caesar', thr=50)
    write('decrypted_images/task8_ctr_50.bmp', encrypted)
    # encr ecb
    encrypted = caesar.encrypt_data(data, key, thr=50)
    write('decrypted_images/task8_ecb_50.bmp', encrypted)
예제 #20
0
def task5():
    filename = 'images/z1_caesar_cbc_c_all.bmp'
    encrypted_data = read(filename)
    key = 223
    iv = 59
    decrypted = cbc_decrypt(encrypted_data, iv, key, type='caesar')
    write('decrypted_images/task5.bmp', decrypted)

    # encryption of task5.bmp using CBC except first 50 bytes
    data = read('decrypted_images/task5.bmp')
    encrypted = cbc_encrypt(data, iv, key, type='caesar', thr=50)
    write('decrypted_images/task5_cbs_50.bmp', encrypted)
    # encryption of task5.bmp using ECB except first 50 bytes
    encrypted = caesar.encrypt_data(data, key, thr=50)
    write('decrypted_images/task5_ecb_50.bmp', encrypted)
예제 #21
0
def task3():
    encrypted_data = read('c3_subst_c_all.png')
    decrypted_data = substitution.decrypt(encrypted_data)
    write('./imgs/task3_decrypted.png', decrypted_data)
예제 #22
0
def task8():
    encrypted_data = read('./imgs/im6_vigener_c_all.bmp')
    decrypted_data = decrypt(encrypted_data, 'magistr')
    write('./imgs/task8_decrypted.bmp', decrypted_data)
예제 #23
0
def task8_plus():
    bmp_data = read('task8_decrypted.bmp')
    encrypted_data = encrypt(bmp_data, 'magistr', border=50)
    print(bmp_data[:50] == encrypted_data[:50])
    write('./imgs/task8_encr50.bmp', encrypted_data)