SHARE
TWEET

Untitled

a guest Sep 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. def substitution_cipher(source: str, sub: str, alphabet: str) -> str:
  3.     alphabet_to_number = {alphabet[index]: index for index in range(0, len(alphabet))}
  4.     number_to_substitution = {index: sub[index] for index in range(0, len(sub))}
  5.     result = ''
  6.     for letter in source.upper():
  7.         index = alphabet_to_number[letter]
  8.         result += number_to_substitution[index]
  9.     return result
  10.  
  11. alphabet = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ '
  12. sub = 'СОУМКХЧИЩЖЪДЭВЯАБЮГ ЕЬЗШЙЦЁФНТПРЫЛ'
  13.  
  14. sourse = str(input())
  15.  
  16. encoded = substitution_cipher(sourse, sub, alphabet)
  17. print("Encoded: ", encoded)
  18. decoded = substitution_cipher(encoded, alphabet, sub)
  19. print("Decoded:", decoded)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top