Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. def poczatek(tekst):
  2.     tekst=tekst.replace(" ","")
  3.     tekst=tekst.lower()
  4.     return tekst
  5.  
  6. def szyfrcezara(tekst,przesuniecie):
  7.     nowy=""
  8.     x=len(tekst)
  9.     for i in range (0,x):
  10.         y=ord(tekst[i])+przesuniecie
  11.         if y>122:
  12.             y=96+(y-122)
  13.         nowy=nowy+chr(y)
  14.     return nowy
  15.  
  16. def odszyfrcezara(tekst,n):
  17.     nowy=""
  18.     x=len(tekst)
  19.     for i in range(0,x):
  20.         y = ord(tekst[i]) - n
  21.         if y < 97:
  22.             y = 123 - (97-y)
  23.         nowy = nowy + chr(y)
  24.     return nowy
  25.  
  26. def podstawieniowy(tekst,alfabet):
  27.   x=len(tekst)
  28.   nowy=""
  29.   for i in range(0,x):
  30.       y=ord(tekst[i])
  31.       nowy=nowy+alfabet[y-97]
  32.   return nowy
  33.  
  34. def odpodsatwieniowy(tekst,alfabet):
  35.     stary=""
  36.     x=len(tekst)
  37.     for i in range(0,x):
  38.         stary=stary+chr(97+alfabet.find(tekst[i]))
  39.     return stary
  40.  
  41. n=int(input("Podaj przesunięcie:"))
  42. tekst1=input("podaj tekst:")
  43. tekst1=poczatek(tekst1)
  44. print(szyfrcezara(tekst1,n))
  45. tekst2=szyfrcezara(tekst1,n)
  46. print(odszyfrcezara(tekst2,n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement