Advertisement
lalkaed

Substitution

Nov 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import string
  2.  
  3.  
  4. def substCipher(text, alph, alphabet):
  5.     res = list(text)
  6.     alphTemp = list(alph)
  7.     for i in range(0, len(text)):
  8.         res[i] = alphTemp[alphabet.index(res[i])]
  9.     return res
  10.  
  11.  
  12. def substDecipher(text, alph, alphabet):
  13.     tmp = list(alphabet)
  14.     res = list(text)
  15.     alphTemp = list(alph)
  16.     for i in range(0, len(text)):
  17.         res[i] = tmp[alphTemp.index(res[i])]
  18.     return res
  19.  
  20. alphabet = "abcdefghijklmnopqrstuvwxyz"
  21. print("Enter your message: ")
  22. mes = str(input())
  23. #print("Enter new alphabet: ")
  24. #alphabetNew = str(input())
  25. alphabetNew = "zaqwsxcderfvbgtyhnmjuiklop"
  26. mes = mes.lower()
  27. mes = mes.replace(' ', '')
  28. result = ''.join(substCipher(mes, alphabetNew, alphabet))
  29. print(result)
  30. resultDecipher = ''.join(substDecipher(result, alphabetNew, alphabet))
  31. print(resultDecipher)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement