Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cipher(string, shift):
- output = ""
- for letter in string:
- if ord(letter) >= ord('a') and ord(letter) <= ord('z'):
- code = ((ord(letter) - ord('a'))+shift)%(ord('z')-ord('a')+1) + ord('a')
- output += chr(code)
- elif ord(letter) >= ord('A') and ord(letter) <= ord('Z'):
- code = ((ord(letter) - ord('A'))+shift)%(ord('Z')-ord('A')+1) + ord('A')
- output += chr(code)
- else:
- output += letter
- return output;
- def decipher(string, shift):
- return cipher(string, -shift)
- def main():
- string = "Ala ma kota, sierotka ma ryzsia"
- shift = 3
- print "Tekst do zaszyfrowania: " + string
- string = cipher(string, shift)
- print "Tekst zaszyfrowany: " + string
- string = decipher(string, shift)
- print "Tekst odszyfrowany: " + string
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment