Advertisement
warmi12

trre

Jan 30th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Szyfrowanie tekstu z dowolnym przesunieciem
  3. #
  4. # Szyforwanie tekstu algorytmem ROT13 (dla wartosci przesuniecia 13,
  5. # deszyfrowanie użyciem drugi raz wartosci 13 lub -13)
  6. #
  7. # Szyforwanie tekstu algorytmem Cezara (dla wartosci przesuniecia 3,
  8. # deszyfrowanie użyciem wartości -3)
  9. #
  10. # Dziala dla duzych i malych liter
  11. # www.algoyrmt.org
  12.  
  13.  
  14. #def przesunLitere(c, n, alf):
  15. # if c in alf:
  16. # oldIdx = alf.index(c) #znajdz indeks
  17. # newIdx = (oldIdx + n) % len(alf) #przesun indeks z dzieleniem modulo o dlugosc alfabetu (aby nie wyjsc poza zakres)
  18. # return alf[newIdx]
  19.  
  20.  
  21.  
  22. #def odszyfrLitere(c,n,alf):
  23. # if c in alf:
  24. # oldIdx=alf.index(c)
  25. # newIdx=(oldIdx-n)%len(alf)
  26. # return alf[newIdx]
  27.  
  28.  
  29. #def odszyfr(word,n=0,alf=string.ascii_lowercase):
  30. # alfLower=alf.lower()
  31. # alfUpper=alf.upper()
  32. # result=""
  33. # for c in word:
  34. # if c in alfLower:
  35. # result += odszyfrLitere(c, n, alfLower)
  36. # elif c in alfUpper:
  37. # result += odszyfrLitere(c, n, alfUpper)
  38. # else:
  39. # result += c
  40. # return result
  41.  
  42.  
  43. #def przesun(word, n=0, alf = string.ascii_lowercase): #zwraca wynik z małymi literami
  44. # word = word.lower()
  45. # result = ""
  46. # for c in word:
  47. # if c in alf:
  48. # result += przesunLitere(c, n, alf)
  49. # else:
  50. # result += c
  51. # return result
  52.  
  53. #def przesun2(word, n=0, alf = string.ascii_lowercase): #zwraca wynik, zachowujac wielkosc liter
  54. # alfLower = alf.lower()
  55. # alfUpper = alf.upper()
  56. # result = ""
  57. # for c in word:
  58. # if c in alfLower:
  59. # result += przesunLitere(c, n, alfLower)
  60. # elif c in alfUpper:
  61. # result += przesunLitere(c, n, alfUpper)
  62. # else:
  63. # result += c
  64. # return result
  65.  
  66. #Szyfr Cezara
  67. #def przesunCezar(word):
  68. # return przesun2(word, 3)
  69.  
  70. #Szyfr ROT-13
  71. #def przesunRot13(word):
  72. # return przesun2(word, 13)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement