Last active
March 1, 2021 10:08
-
-
Save ktprezes/6e38dbc2f3df4a201db51d2f46803d61 to your computer and use it in GitHub Desktop.
Python - Szyfr Cezara - przykładowa implementacja - (Caesar cipher naive implementation)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
# Szyfr Cezara - przykładowa implementacja | |
# dla zdekodowania zaszyfrowanego tekstu trzeba podać przesunięcie o przeciwnym znaku | |
# np: kodowanie z przesunięciem '7', to dekodowanie - z przesunięciem '-7' | |
# lub kodowanie z przesunięciem '-100', to dekodowanie - z przesunięciem '100' | |
alfabet = 'aAąĄbBcCćĆdDeEęĘfFgGhHiIjJkKlLłŁmMnNńŃoOóÓpPqQrRsSśŚtTuUvVwWxXyYzZźŹżŻ' | |
tekst_we ="" | |
tekst_wy ="" | |
znak ="" | |
przes = 0 | |
indx = 0 | |
while(1): | |
tekst_we = input("Podaj tekst: ") | |
if tekst_we == "" : | |
break | |
przes = int(input("Podaj przesunięcie: ")) | |
tekst_wy = "" | |
for znak in tekst_we: | |
indx = alfabet.find(znak) | |
if indx != -1 : | |
tekst_wy += alfabet[ (indx + przes) % len(alfabet) ] | |
else: | |
tekst_wy += znak | |
print("Tekst wyjściowy to: " + tekst_wy) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jak odszyfrować i zakończyć program?