fork(2) download
  1. # Шифрование текста с помощью сдвига Цезаря
  2.  
  3. strOfChar = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ' . , : ; # № : $ = - + * /"
  4. listOfChar = strOfChar.lower().split(" ")
  5.  
  6. text = "This post tells in simple language about the essence of Caesar's encryption. Physics.Math.Code.Books is the best group for physicists, mathematicians and developers in VK"
  7.  
  8. """ Метод, шифрующий слово """
  9. def encryptedWord(word, k):
  10. wordEncrypted = ''
  11. for ch in word:
  12. if(ch.isupper()):
  13. indexOfChar = (listOfChar.index(ch.lower()) - k) % len(listOfChar)
  14. wordEncrypted += listOfChar[indexOfChar].upper()
  15. else:
  16. indexOfChar = (listOfChar.index(ch) - k) % len(listOfChar)
  17. wordEncrypted += listOfChar[indexOfChar]
  18. return wordEncrypted
  19.  
  20. """ Метод, дешифрующий слово """
  21. def decryptedWord(word, k):
  22. wordDecrypted = ''
  23. for ch in word:
  24. if(ch.isupper()):
  25. indexOfChar = (listOfChar.index(ch.lower()) + k) % len(listOfChar)
  26. wordDecrypted += listOfChar[indexOfChar].upper()
  27. else:
  28. indexOfChar = (listOfChar.index(ch) + k) % len(listOfChar)
  29. wordDecrypted += listOfChar[indexOfChar]
  30. return wordDecrypted
  31.  
  32.  
  33.  
  34. """ Метод, шифрующий текст в виде строки """
  35. def encryptedText(string, k):
  36. encryptStr = ''
  37. for word in string.split(" "):
  38. encryptStr += encryptedWord(word, k) + " "
  39. return encryptStr[:-1]
  40.  
  41. """ Метод, дешифрующий текст в виде строки """
  42. def decryptedText(string, k):
  43. decryptStr = ''
  44. for word in string.split(" "):
  45. decryptStr += decryptedWord(word, k) + " "
  46. return decryptStr[:-1]
  47.  
  48.  
  49. print("Исходные текст: ", text)
  50. k = 1 #Ключ шифрования
  51. print("Зашифрованный текст: ", encryptedText(text, k))
  52. print("Расшифрованный текст: ", decryptedText(encryptedText(text, k), k))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
Исходные текст:  This post tells in simple language about the essence of Caesar's encryption. Physics.Math.Code.Books is the best group for physicists, mathematicians and developers in VK
Зашифрованный текст:  Sghr onrs sdkkr hm rhlokd k/mft/fd /ants sgd drrdmbd ne B/dr/qzr dmbqxoshnm' Ogxrhbr'L/sg'Bncd'Annjr hr sgd adrs fqnto enq ogxrhbhrsr. l/sgdl/shbh/mr /mc cdudknodqr hm UJ
Расшифрованный текст:  This post tells in simple language about the essence of Caesar's encryption. Physics.Math.Code.Books is the best group for physicists, mathematicians and developers in VK