Advertisement
furas

Python - encryption

Feb 16th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  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.     input_filename  = 'text.txt'
  16.     output_filename = 'encryption_words.txt'
  17.  
  18.     encrypted_text = ''
  19.  
  20.     with open(input_filename) as file_in:
  21.         oryginal_text = file_in.read()
  22.        
  23.         for char in oryginal_text:
  24.             if char in codes:
  25.                 encrypted_text += codes[char]
  26.                  
  27.         print('oryginal:')
  28.         print(oryginal_text)
  29.         print('---')
  30.         print('encrypted:')
  31.         print(encrypted_text)
  32.  
  33.     with open(output_filename, 'w') as file_out:
  34.         for i in range(0, len(encrypted_text), 50):
  35.             file_out.write(encrypted_text[i:i+50])
  36.             file_out.write('\n')
  37.  
  38.     print('---')
  39.     print('Encrypted words save to', output_filename)
  40.  
  41.     with open(output_filename) as file_in:
  42.         print(file_in.read())
  43.    
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement