Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Szyfr Cezara - kodowanie i odkodowanie"""
- import sys
- def szyfrow(tekst, krok):
- stekst=""
- for i in range(len(tekst)):
- #drukowane
- if(ord(tekst[i])>=65 & ord(tekst[i])<=90):
- if(ord(tekst[i])+krok >90):
- nowy1 = (ord(tekst[i])+krok - 26)
- stekst += chr(nowy1)
- else:
- nowy2 = ord(tekst[i]) + krok
- stekst += chr(nowy2)
- #male
- elif(ord(tekst[i])>=97 & ord(tekst[i])<=122):
- if(ord(tekst[i])+krok >122):
- nowy1 = (ord(tekst[i])+krok - 26)
- stekst += chr(nowy1)
- else:
- nowy2 = ord(tekst[i]) + krok
- stekst += chr(nowy2)
- #spacja
- elif(ord(tekst[i])==32):
- nowy = 32
- stekst += chr(nowy)
- else:
- print "Wpisales nieprawidlowy znak/znaki! Sprobuj ponownie"
- return stekst
- def deszyfrow(tekst, krok):
- dtekst=""
- for i in range(len(tekst)):
- #drukowane
- if(ord(tekst[i])>=65 & ord(tekst[i])<=90):
- if(ord(tekst[i])-krok <65):
- nowy1 = (ord(tekst[i])-krok + 26)
- dtekst += chr(nowy1)
- else:
- nowy2 = ord(tekst[i]) - krok
- dtekst += chr(nowy2)
- #male
- elif(ord(tekst[i])>=97 & ord(tekst[i])<=122):
- if(ord(tekst[i])-krok <97):
- nowy1 = (ord(tekst[i])-krok + 26)
- dtekst += chr(nowy1)
- else:
- nowy2 = ord(tekst[i]) + krok
- dtekst += chr(nowy2)
- #spacja
- elif(ord(tekst[i])==32):
- nowy = (ord(tekst[i]))
- dtekst += chr(nowy)
- else:
- print "Wpisales nieprawidlowy znak/znaki! Sprobuj ponownie"
- return dtekst
- krok = int(input("Podaj krok:\n"))
- tekst = raw_input("Podaj tekst:\n")
- print szyfrow(tekst,krok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement