View difference between Paste ID: uP3yxDsT and KrSfCF3A
SHOW: | | - or go back to the newest paste.
1-
# File encryption
1+
2-
# Use dictionary to assign codes to each letter of the alphabet
2+
3
    codes = {'A':'!', 'a':'0', 'B':'@', 'b':'9', 'C':'#',
4
             'c':'8', 'D':'$', 'd':'7', 'E':'%', 'e':'6',
5
             'F':'^', 'f':'5', 'G':'&', 'g':'4', 'H':'*',
6
             'h':'3', 'I':';;', 'i':'2', 'J':'~', 'j':'1',
7
             'K':'x', 'k':'?', 'L':'b', 'l':'Y', 'M':'e',
8
             'm':'q', 'N':'a', 'n':'c', 'O':'f', 'o':'D',
9
             'P':'j', 'p':'G', 'Q':'B', 'q':'J', 'R':'K',
10
             'r':'E', 'S':'A', 's':'d', 'T':'I', 't':'L',
11
             'U':'C', 'u':'>', 'V':'<', 'v':'/', 'W':'F',
12
             'w':'k', 'X':'r', 'x':'R', 'Y':'t', 'y':'o',
13
             'Z':'n', 'z':'s', ' ':' '}
14
15-
             'Z':'n', 'z':'s', ' ': ' '}
15+
    input_filename  = 'text.txt'
16
    output_filename = 'encryption_words.txt'
17-
    # Create an empty string to stored the encryption.
17+
 
18-
    encrypted_words = ''
18+
    encrypted_text = ''
19
 
20-
    # Open file for reading
20+
    with open(input_filename) as file_in:
21-
    text_file = 'text.txt'
21+
        oryginal_text = file_in.read()
22-
    with open(text_file) as file_object:
22+
       
23-
        encrypted = file_object.read()
23+
        for char in oryginal_text:
24-
        
24+
            if char in codes:
25-
        # Perform the encryption
25+
                encrypted_text += codes[char]
26-
        i = 0
26+
                  
27-
        while encrypted !='' and i < len(encrypted):
27+
        print('oryginal:')
28-
            if encrypted[i] in codes:
28+
        print(oryginal_text)
29-
                encrypted_words += codes[encrypted[i]]
29+
        print('---')
30-
            elif encrypted[i] == ' ':
30+
        print('encrypted:')
31-
                encrypted_words += ' '
31+
        print(encrypted_text)
32-
            i += 1
32+
 
33-
        print(encrypted)
33+
    with open(output_filename, 'w') as file_out:
34-
        print()
34+
        for i in range(0, len(encrypted_text), 50):
35-
        print(encrypted_words)
35+
            file_out.write(encrypted_text[i:i+50])
36
            file_out.write('\n')
37-
    # Write encrypted_words to a text file.
37+
 
38-
    encrypted_file = 'encryption_words.txt'
38+
    print('---')
39-
    with open(encrypted_file, 'w') as encrypted_object:
39+
    print('Encrypted words save to', output_filename)
40-
        for i in range(len(encrypted_words)):
40+
41-
            encrypted_object.write('{:50}\n'.format(encrypted_words[i]))
41+
    with open(output_filename) as file_in:
42
        print(file_in.read())
43-
    print()
43+
   
44-
    print('Encrypted words save to encryption_words.txt')
44+