Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. """Szyfr Cezara - kodowanie i odkodowanie"""
  2. import sys
  3.  
  4. def szyfrow(tekst, krok):
  5.     stekst=""
  6.     for i in range(len(tekst)):
  7.         #drukowane
  8.         if(ord(tekst[i])>=65 & ord(tekst[i])<=90):
  9.             if(ord(tekst[i])+krok >90):
  10.                 nowy1 = (ord(tekst[i])+krok - 26)
  11.                 stekst += chr(nowy1)
  12.             else:
  13.                 nowy2 = ord(tekst[i]) + krok
  14.                 stekst += chr(nowy2)
  15.         #male
  16.         elif(ord(tekst[i])>=97 & ord(tekst[i])<=122):
  17.             if(ord(tekst[i])+krok >122):
  18.                 nowy1 = (ord(tekst[i])+krok - 26)
  19.                 stekst += chr(nowy1)
  20.             else:
  21.                 nowy2 = ord(tekst[i]) + krok
  22.                 stekst += chr(nowy2)
  23.         #spacja
  24.         elif(ord(tekst[i])==32):
  25.             nowy = 32
  26.             stekst += chr(nowy)
  27.         else:
  28.             print "Wpisales nieprawidlowy znak/znaki! Sprobuj ponownie"
  29.     return stekst
  30.  
  31. def deszyfrow(tekst, krok):
  32.     dtekst=""
  33.     for i in range(len(tekst)):
  34.         #drukowane
  35.         if(ord(tekst[i])>=65 & ord(tekst[i])<=90):
  36.             if(ord(tekst[i])-krok <65):
  37.                 nowy1 = (ord(tekst[i])-krok + 26)
  38.                 dtekst += chr(nowy1)
  39.             else:
  40.                 nowy2 = ord(tekst[i]) - krok
  41.                 dtekst += chr(nowy2)
  42.         #male
  43.         elif(ord(tekst[i])>=97 & ord(tekst[i])<=122):
  44.             if(ord(tekst[i])-krok <97):
  45.                 nowy1 = (ord(tekst[i])-krok + 26)
  46.                 dtekst += chr(nowy1)
  47.             else:
  48.                 nowy2 = ord(tekst[i]) + krok
  49.                 dtekst += chr(nowy2)
  50.         #spacja
  51.         elif(ord(tekst[i])==32):
  52.             nowy = (ord(tekst[i]))
  53.             dtekst += chr(nowy)
  54.         else:
  55.             print "Wpisales nieprawidlowy znak/znaki! Sprobuj ponownie"
  56.     return dtekst
  57.  
  58. krok = int(input("Podaj krok:\n"))
  59. tekst = raw_input("Podaj tekst:\n")
  60.  
  61. print szyfrow(tekst,krok)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement